Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: Problem with a for loop

$
0
0
On 10/25/2012 9:59 AM, Giorgio Monti wrote:
> Hi,
>
> I'm a student and I need help on this case:
>
> I have a matrix "V" with N = 100 rows and T = 30 columns which describes
> the value of a fund for 30 years. The expenditure that the fund have to
> do for the next year should be the arithmetic mean of the last three
> years fund's value. This is inside a for loop, so i have to do this for
> 30 years (T), N times. I tried the code below, but it does'nt work:
>
> for t = 1: T
> E (1: N, t +1) = (mean (V (1: N, t: t-2), 2)));

E=zeros(size(V,1),size(V,2)-2)); % preallocate
for t=3:size(V,2)
   E(:,t-2)=mean(V(:,t-2:t),2);
end

--

Viewing all articles
Browse latest Browse all 19628

Trending Articles