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)
AKASH TYAGI
AKASH TYAGI on 7 Jun 2022
Commented: Stephen23 on 8 Jun 2022
  4 Comments
Stephen23
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.

Sign in to comment.

Accepted Answer

Dyuman Joshi
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
  3 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!