How to store multiple output tables in a cell array
Show older comments
Hi everyone:
I have some output data stored in tabular format in .txt/csv files (file name format, IEA-15-240-RWT-UMaineSemi100m45mpsSNS 'file number'-'bachnumber'.out). The tables are stored in batches from 0:30:330 (30 increments). Each batch cotains 6 tables. Hence 0 contains six tables/files, numbered 1:6. I am able to store the data/file for one batch in a cell array like this:
for ii=1:6
OutputData{ii,1} = readtable(['IEA-15-240-RWT-UMaineSemi100m45mpsSNS',num2str(ii),'-0.out'],'FileType',"text",'HeaderLines',8,"ReadVariableNames",0);
OutputData{ii,1} = table2array(OutputData{ii,1});
end
However this is just for the 0 batch. I would like to formualte the code such that the tables from all batches are stored in a cell array or other appropriate storage method. I tried the following:
for ii=1:2
for jj=0:30
OutputData{jj}{ii,1} = readtable(['IEA-15-240-RWT-UMaineSemi100m43mpsJCS',num2str(ii),'-',num2str(jj)','.out'],'FileType',"text",'HeaderLines',8,"ReadVariableNames",0);
OutputData{jj}{ii,1} = table2array(OutputData{jj}{ii,1});
end
end
But rceived the folowing error:
"Unable to perform assignment because brace indexing is not supported for variables of this type."
Numerous attempts to solve this problem have failed. I would be grateful if someone could give some guidance to help me to solve it.
Thank you.
Regards,
AOAW
1 Comment
Walter Roberson
on 27 May 2022
Did you clear OutputData? Before the loop it exists but it is not a cell.
Note that you cannot index at j=0
Accepted Answer
More Answers (1)
Image Analyst
on 27 May 2022
I suggest you simply things by creating intermediate variables. Trying to index a 2-D cell array inside a cell of another, outer 2-D cell array like
OutputData{jj}{ii,1}
is just getting way too complicated for me to understand. Try something simpler like perhaps this:
fCounter = 1;
for f = 0 : 30 : 330 % Loop over files.
for b = 1 : 6 % Loop over 6 batches.
thisFileName = sprintf('IEA-15-240-RWT-UMaineSemi100m43mpsJCS%d-%d.out', f, b);
if ~isfile(thisFileName)
% Skip it if the file does not exist.
fprintf('File does not exist: "%s".\n', thisFileName);
continue;
end
thisTable = readtable(thisFileName,'FileType',"text",'HeaderLines',8,"ReadVariableNames",0);
OutputData{b, fCounter} = table2array(thisTable);
end
fCounter = fCounter + 1;
end
3 Comments
Andre White
on 27 May 2022
Image Analyst
on 27 May 2022
OK. You accepted an answer already so I guess you got it all figured out so I won't put any more effort towards this.
Andre White
on 30 May 2022
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!