MATLAB Huge data manipulation in Matlab

AI Thread Summary
The discussion centers on the challenge of importing and manipulating a large number of matrices from Excel into MATLAB. The user has 5000 matrices, each stored in separate Excel sheets, and seeks to automate the naming convention for these matrices in MATLAB, assigning names like A1, A2, A3, etc. The main goal is to perform operations on these matrices within loops, such as adding matrices that are a specific number of steps apart. The solution proposed involves using the 'eval' command, which allows for dynamic variable naming and manipulation based on constructed strings. An example is provided where matrices are created in a loop using 'eval' to define their names and values. This approach facilitates the desired operations on the matrices by enabling the user to reference them programmatically within MATLAB.
Physics_wiz
Messages
227
Reaction score
0
I have about 5000 matrices which are all in excel. I need to put them all in Matlab so I can use them in programs. Every one of the 5000 matrices will be in its own excel sheet and they will all be saved in a folder. I don't mind reading them one by one in Matlab, but the thing I am having trouble with is manipulating the names of the matrices. For example, I want the first matrix to be called A1, the second to be called A2, third A3, etc... After all those are in Matlab, I want to do operations such as Ax(:,2)+A(x+1)(:,5) inside loops.

My main question is, can I somehow make a vector of just the names (i.e. names = [A1 A2 A3...A5000] and then use those in loops? Say I want to add every matrix to the one 5 steps after it like, B1 = A1+A6, B2 = A2+A7, etc... how can I use matrix names inside a loop?
 
Last edited:
Physics news on Phys.org
It sounds to me like you want to use the 'eval' command. It allows you to assign things to and operate on variables names which are defined in terms of other variables.

For example, if I want to create 5 matrices which are called A1, A2, ..., A5, and have each matrix An be such that An = n*eye(n), I would write

Code:
for n = 1:5
eval(['M' num2str(n) ' = n*eye(n)' ])
end
 
Ahh I see. Thank you so much :smile:.
 

Similar threads

Replies
18
Views
6K
Replies
3
Views
2K
Replies
1
Views
2K
Replies
5
Views
3K
Replies
7
Views
1K
Replies
8
Views
5K
Replies
12
Views
2K
Replies
12
Views
3K
Replies
3
Views
3K
Back
Top