Change the name of array in each iteration

I would like to group together in a Matrix some data for each year. For example for year 2000 i would like to create the Matrix C_2000 for 2001 C_2001 etc. My code is the following, my problem is that i don't know how i should write the name of the matrix, since when i am using C_ye Matlab doesn't understand ye like a variable.
for yy=2000:2010
ye=num2str(yy);
C_ye=[];
path =strcat('e:\test\',ye,'\');
filefolder=strcat(path,'*.dat');
files=dir(filefolder);
for i=1:length(files)
filename=strcat(path,files(i).name);
yr=filename(42:43);
doy=filename(39:41);
doy=str2double(doy);
yr=str2double(yr);
A=importdata(filename);
B=A.data;
hh=floor(B(:,1));
mm=floor((B(:,1)-hh)*60);
ss=((B(:,1)-hh)*60-mm)*60;
mm=round(mm+ss/60);
yr=repmat(yr,size(B,1),1);
doy=repmat(doy,size(B,1),1);
C_ye=[C_ye yr doy hh mm B(:,2)];
end
cleavars -except C_ye
end
Thank you, Kostas

 採用された回答

Sean de Wolski
Sean de Wolski 2011 年 12 月 6 日

1 投票

Don't Do It!
FAQ:4.6
More:
doc cell
is probably a good place to start. As far as simple help, change the () to {};
C = cell(5,1);
for ii = 1:5
C{ii} = magic(ceil(rand*10));
end
% a 5x1 cell array with randomly sized magic squares

3 件のコメント

Kostas
Kostas 2011 年 12 月 6 日
How could i separate each year in a distinct matrix or file then?
David Young
David Young 2011 年 12 月 6 日
Put them in a cell array.
Kostas
Kostas 2011 年 12 月 6 日
Could you help me please because i haven't "worked" with cells, so i have no idea how i could implement it.

サインインしてコメントする。

その他の回答 (1 件)

Kostas
Kostas 2011 年 12 月 6 日

0 投票

Thanks, it seems so simple i just change this part
C = cell(11,1);
for yy=2000:2010
ii=yy-1999;
.....
C{ii}=[yr doy hh mm B(:,2)];
end

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by