MATLAB MATLAB: Calling Out Matrix by Name w/ Index

  • Thread starter Thread starter Curl
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
To reference matrices A1, A2, and A3 dynamically in MATLAB using a loop, direct indexing like A(k) won't work since it attempts to access elements rather than variable names. Instead, two primary methods are suggested: using `genvarname` to create variable names dynamically or utilizing cell arrays for easier implementation. Cell arrays are particularly recommended for their simplicity in managing multiple matrices. This approach allows for effective manipulation and retrieval of matrix data within a loop structure.
Curl
Messages
756
Reaction score
0
If I have a few matrices defined, say A1 A2 A3
I want to use a loop to call out these individually. I can't just do
for k=1:3
B(k) = funct( A(k) )+ etc...
end

since A(k) will call the kth element of "A" but what I want is to refer to the name of the matrix (by the number next to the letter A). So how do I call out a matrix by name in MATLAB using and index?
 
Physics news on Phys.org

Similar threads

Replies
32
Views
4K
Replies
2
Views
2K
Replies
6
Views
2K
Replies
6
Views
2K
Replies
4
Views
2K
Replies
2
Views
1K
Replies
3
Views
2K
Replies
1
Views
2K
Replies
4
Views
2K
Back
Top