How to save multiple matrices in multiple files? I solved the first two parts using for loop but couldn't do the 3rd one.How to save these multiple matrices in separate files?
조회 수: 2 (최근 30일)
이전 댓글 표시
댓글 수: 4
Stephen23
2022년 6월 8일
"So challenge remaining is store the magic matrices in different names say A1, A2 etc. "
You could do that if you want to force yourself into writing slow, complex, inefficient, obfuscated, buggy code that is difficult to debug.
Or you could:
- just write each array to file, without storing them all, or
- use indexing, which is neat, simple, and very efficient.
채택된 답변
Dyuman Joshi
2022년 6월 8일
편집: Dyuman Joshi
2022년 6월 8일
%Saving magic matrices in files
for n=1:7
A=magic(5*n+15);
filenames=sprintf('magicmatrix_%d.mat',n);
save(filenames);
end
%clear workspace variables
clear all
%Loading saved files
for j=1:7
filenamel=sprintf('magicmatrix_%d.mat',j);
y=load(filenamel,'A');
figure %creates a new figure window
image(y.A) %display image
end
댓글 수: 3
추가 답변 (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!