Problem with a loop for

Hi,
I'm a student and I need help on this case:
I a matrix V of N = 100 rows and T = 30 columns which describes the value of a fund for 30 years. The next year expenditure that the fund has to do 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
S(1: N, t +1) = (mean (V (1: N, t: t-2), 2)));
end
Can you help me?
Thanks

답변 (2개)

Matt J
Matt J 2012년 10월 25일
편집: Matt J 2012년 10월 25일

0 개 추천

I don't know what you want to do for Year 1 which doesn't have prior year data to average. Are you sure you don't want to start this at Year 4? If so, this is one possibility,
S=conv2(V,[0 1 1 1]/3,'valid')
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 25일
편집: Azzi Abdelmalek 2012년 10월 25일

0 개 추천

T=30;
N=100;
V=rand(N,T); % Example
out=cell2mat(arrayfun(@(x) mean(V(:,max(x-4,1):max(x-1,1)),2),1:T,'un',0));

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2012년 10월 25일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by