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!
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!