how to load matrices from mat file
13 views (last 30 days)
Show older comments
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
Accepted Answer
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
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.
More Answers (0)
See Also
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!