How to save lots of 3D matrix obtained from a for loop in matlab

1 次查看(过去 30 天)
Hi , I am new in matlab. I have a code , X=zreos(L); F=find(L==1);X(F)=1; among which L is a 3D label matrix, and the lagrest label value in L is 100. I want to conduct F=find(L=1,2,3...100), and X(F)=1. Could you please tell me how to achieve this? And after this, I will get 100 3D matrix, how should I save them in a folder? Thank you very much! I use the follow code, but it did't work.
N=100
for i=1:100
Xi=zeros(L);
Fi=find(L==i);
Xi(Fi)=1;
fnm=strcat('Xi','.mat');
save(C:Desktop\fnm,'Xi');
end
Could you please help me? Thanks in advance!

采纳的回答

Bob Thompson
Bob Thompson 2019-4-22
'Could you please tell me how to achieve this?'
It seems like you have done this already. Is there something not working in the code you posted to find and make the appropriate values?
'And after this, I will get 100 3D matrix, how should I save them in a folder?'
What you do with your results is entirely dependant on how you want to use it in the future. I suspect you do not want a large number of files here though, and would suggest simply indexing the results into the 'fourth' dimension.
N=100
for i=1:100
tmp=zeros(L);
Fi=find(L==i);
tmp(Fi)=1;
Xi(:,:,:,i) = tmp;
end
  1 个评论
XF
XF 2019-4-22
@Bob Nbob Thank you so much for your help! Yes I have checked my code , it now works! Thank you so much for your save method!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by