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

1 回表示 (過去 30 日間)
XF
XF 2019 年 4 月 22 日
コメント済み: XF 2019 年 4 月 22 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by