how to load matrices from mat file

13 views (last 30 days)
Sophi gra
Sophi gra on 12 Jul 2016
Edited: Stephen23 on 12 Sep 2023
I have 500 matrices named A1B'1....20'C'1...25' in mat format. I need to make them look like A1BiCj( where i=1:20 and j=1:25) to do function on them. does anyone knows how I can do it?!
  8 Comments
Rena Berman
Rena Berman on 11 Jun 2019
(Answers Dev) Restored edit

Sign in to comment.

Accepted Answer

Thorsten
Thorsten on 12 Jul 2016
load yourmatfile.mat
for i = 1:20
for j = 1:25
eval(['A1(:,:,' int2str(i) ',' int2str(j) ') = A1B' int2str(i) 'C' int2str(j) ';'])
end
end
Now you can access A1B10C13 as
A1(:,:,10,13)
  3 Comments
Thorsten
Thorsten on 12 Jul 2016
No, just the names. Use the approach I outlined above.
Stephen23
Stephen23 on 12 Sep 2023
Edited: Stephen23 on 12 Sep 2023
Note that the EVAL documentation recommends only calling EVAL on the RHS if possible:
which also makes this answer simpler:
for i = 1:20
for j = 1:25
A1(:,:,i,j) = eval(['A1B',int2str(i),'C',int2str(j)]);
end
end
Even better would be to avoid the situation by LOADing into output variables.

Sign in to comment.

More Answers (0)

Categories

Find more on Variables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!