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 views (last 30 days)
Show older comments

4 Comments
Stephen23
on 8 Jun 2022
"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.
Accepted Answer
Dyuman Joshi
on 8 Jun 2022
Edited: Dyuman Joshi
on 8 Jun 2022
%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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!