matlab - Name each variable differently in a loop -


i have created .dat file of file names. want read matlab each file in list , give data different name. currently, each iteration overwrites last one.

i found lot of people give answer:

for i=1:10   a{i} = 1:i; end 

however, isn't working problem. here's doing

flist = fopen('fnames.dat'); % open list of file names  nt = 0; % counter go 1 each file loaded while ~feof(flist) % while end of file has not been reached     = 1:6 % number of filenames in .dat file      % each file     fname = fgetl(flist); % reads next line of list, name of next data file     disp(fname); % stores name string in fname      nt = nt+1; % time index      % save data      data{i} = read_mixed_csv(fname, '\t'); % reads in csv file% open file     data{i} = data(2:end,:); % replace header row      end end 

the code runs no errors, 1 data variable saved.

my fnames.dat contains this: ia_2007_mda8_o3.csv in_2007_mda8_o3.csv mi_2007_mda8_o3.csv mn_2007_mda8_o3.csv oh_2007_mda8_o3.csv wi_2007_mda8_o3.csv

if possible, name data more intuitive. ia first file, in second , on. there way this?

the last line of loop problem:

data{i} = data(2:end,:); 

i don't know happens did not run code, data(2:end,:) refers second last dataset, not second last line.

try:

thisdata = read_mixed_csv(fname, '\t'); data{i} = thisdata(2:end,:); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -