Storing multiple matrices in an array
显示 更早的评论
How do I store multiple matrices of identical dimensions but different names in one array?
1 个评论
Stephen23
2017-6-20
Well, actually there is a way to access those variables in a loop, but you might like to first know what the MATLAB documentation says about it: "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended."
You might also like to read what experienced MATLAB users say about what you are trying to do (hint: they strongly advise against it):
A much better solution is to load your data into one variable, and then simply access the data using indexing and/or fieldnames, e.g. if you use load then always load into an output variable. This will more efficient, neater, more robust, easier to check, easier to debug, faster,...
回答(1 个)
Adam
2017-6-20
Depends how you want them to end up. You can pack them into a numeric array of one higher dimension or a cell array (in which it doesn't matter if they are the same size).
A numeric array is always better.
e.g.
A = rand(20,30);
B = rand(20,30);
C = cat( 3, A, B );
3 个评论
John F.
2017-6-20
Adam
2017-6-20
Well, once they are in C you just have 1. How you get hold of them in the first place I don't know, but if you store them directly into the 3d array (with a better name than C) then they are just indices along the 3rd dimension rather than names.
Jan
2017-6-20
@John F: Of course, but it is your turn to know, how your 500 matrices are stored. What about creating a [n x m x 500] array?
类别
在 帮助中心 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!