Huge data manipulation in Matlab

Click For Summary
SUMMARY

The discussion focuses on manipulating a large number of matrices in MATLAB, specifically 5000 matrices stored in individual Excel sheets. The user seeks to dynamically name these matrices (A1, A2, A3, etc.) and perform operations on them using loops. The solution proposed involves using the 'eval' command to create and manipulate variable names programmatically. This method allows for the creation of matrices based on their indices and facilitates operations such as adding matrices that are spaced apart in the sequence.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax
  • Understanding of matrix operations in MATLAB
  • Knowledge of the 'eval' function in MATLAB
  • Basic proficiency in reading data from Excel files into MATLAB
NEXT STEPS
  • Learn how to read multiple Excel sheets into MATLAB using 'readtable' or 'xlsread'
  • Explore advanced MATLAB data structures like cell arrays for storing matrices
  • Investigate the implications of using 'eval' for variable manipulation and alternatives
  • Study MATLAB's vectorization techniques to optimize matrix operations
USEFUL FOR

MATLAB users, data analysts, and researchers dealing with large datasets who require efficient manipulation and operations on multiple matrices.

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 ·
Replies
18
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K