2011 12 2 0 0 0 17.7700000000000
2011 12 1 0 0 0 17.9900000000000
2011 11 30 0 0 0 18.0500000000000
2011 11 29 0 0 0 17.5700000000000
2011 11 28 0 0 0 17.5200000000000
第一列是年份,从2006年到2011年,第七列是价格,要计算每年价格的平均值,小弟试过switch,for+if,都无法计算,下面是我写的for代码,求大神查错,另求其它解决方案,小弟一直用的stata,初学matlab,发现matlab在数据处理上要繁琐许多,同求大神赐教,多谢诸位了。
clear
clc
m=importdata('table.csv',',');
a=struct2cell(m);
b=cell2mat(a(1));
price=b(:,4);
c=m.textdata(:,1);
d=c(2:1261,1);
e=cell2mat(d);
date=datenum(e);
whole=fints(date,price);
re=price2ret(price);
y=quantile(re,[.01 .025 .25 .50 .75 .975 .99]);
time=datevec(date);
data=[time,price];
for i=1:1260
if data(:,1)==2006
me(1,1)=mean(data(:,7));
elseif data(:,1)==2007
me(1,2)=mean(data(:,7));
elseif data(:,1)==2008
me(1,3)=mean(data(:,7));
elseif data(:,1)==2009
me(1,4)=mean(data(:,7));
elseif data(:,1)==2010
me(1,5)=mean(data(:,7));
else
me(1,6)=mean(data(:,7));
end
end