Clear Filters
Clear Filters

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

1 view (last 30 days)
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!

Accepted Answer

Bob Thompson
Bob Thompson on 22 Apr 2019
'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 Comment
XF
XF on 22 Apr 2019
@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!

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!