Compile multiple matrices into one without listing them all out
Afficher commentaires plus anciens
Heya,
I am trying to put a series of matrices into one file. I can do this by writing each of the number in one by one (but there are lots). Is there a quicker way to do this?
My code so far:
numfiles = 60;
mydata = cell(1,numfiles);
for k = 1:numfiles
myfilename= sprintf('40nMket (%d).txt',k);
mydata{k} = importdata(myfilename);
end
%combine
fulldata = [mydata{1,1}.data, mydata{1,2}.data, mydata{1,3}.data, mydata{1,4}.data, mydata{1,5}.data, mydata{1,6}.data]
^how can I do the above final line without typing all numbers up to 60?
Many thanks
Réponses (1)
"how can I do the above final line without typing all numbers up to 60?"
The general approach is to use a comma-separated list:
numfiles = 60;
mydata = cell(1,numfiles);
for k = 1:numfiles
myfilename= sprintf('40nMket (%d).txt',k);
mydata{k} = importdata(myfilename).data; % changed
end
fulldata = [mydata{:}]
I strongly recommend that you replace IMPORTDATA with READMATRIX.
Catégories
En savoir plus sur Standard File Formats dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!