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!