How to load multiple .mat files into workspace in order to concatenate matrices and calculate mean
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I have multiple correlation matrices (one for each person in my experiment) and am trying to create the mean correlation matrix but don't know how to do this.
I have saved each 11 x 11 correlation matrix as a .mat file and so have one for each subject (201.mat, 202.mat, 203.mat, 204.mat, etc.). The first problem I am running into is loading all of the matrices at once into the matlab workspace in order to concatenate them into a 3-D array and then be able to calculate the mean. Each time I load a new matrix it overwrites the old matrix. How do I load all the matrices into the workspace at once? And then how would I concatenate all the matrices to create a 3-D array and then compute a mean matrix?
Any help would be much appreciated. Thank you.
0 个评论
回答(1 个)
Azzi Abdelmalek
2014-2-10
M=zeros(11,11,10) % for 10 files
p=0;
for k=201:210
p=p+1;
A=load(sprintf('%d.mat',k));
s=fields(A)
M(:,:,p)=A.(s)
end
1 个评论
María Maldonado Gil
2021-10-24
I don´t think this works. I´ve tried on my case and it does not run ok, as it says that is unable to find the .mat files. Don´t know why
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!