Importing matrices in text files and creating a structure with 100 entries
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hello there,
I was hoping that somebody could perhaps help me out with a problem that I have. I'm only learning how to use matlab.
I have 100 4x4 matrices in .txt files in a folder.
How could I import them and create a structure with 100 entries and in each entry there would be one matrix.
The reason I ask is because I'm trying to get the average of these matrices and this post provides a solution if the matrices are in this format.
Thank you for your help
Regards
John
Answers (1)
Sean de Wolski
on 14 Feb 2012
0 votes
Also note, that if they're all the same size, you could stack them along the third dimension and then take the mean of the first and second dimension which would leave you with each matrice's mean.
7 Comments
John
on 14 Feb 2012
Sean de Wolski
on 14 Feb 2012
too much effort, use importdata() and a cell array (you can convert to struct later):
C = cell(100,1);
for ii = 1:100
C{ii} = importdata(filename(ii))
end
John
on 14 Feb 2012
Sean de Wolski
on 14 Feb 2012
importdata(['matrix' num2str(ii) '.txt'])
John
on 15 Feb 2012
Sean de Wolski
on 15 Feb 2012
You're welcome!
Were you able to get it working?
John
on 15 Feb 2012
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!