Extract column from a set of matrices
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Carlos Imbaquingo
il 30 Nov 2019
Modificato: Stephen23
il 1 Dic 2019
I have a bunch of matrices that are named 'TAGi', where i is an index from 1 to 2500. The size of each matrix is 3000 x 4. I need to get the third column to evaluate the rms value. How can I extract the third column of every single matrix with a for loop?
1 Commento
Stephen23
il 30 Nov 2019
Modificato: Stephen23
il 30 Nov 2019
"I have a bunch of matrices that are named 'TAGi', where i is an index from 1 to 2500."
What you describe is not an index, but in numbered variables.
Numbered variables are a sign that you are doing something wrong.
Accessing numbered variable names is one way that beginners force themselves into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this to know why:
In contrast, actual indexing is neat, simple, and very efficient (unlike what you are trying to do).
The best solution to your problem would be to not have 2500 individual variables in the workspace: most likely you did not define them all by hand, so you must have generated them or imported them somehow. So the most important question is: how did you get those variables into the workspace? For example, if they were load-ed then you can easily load into an output variable and avoid this entire problem.
Risposta accettata
Carlos Imbaquingo
il 1 Dic 2019
1 Commento
Stephen23
il 1 Dic 2019
Modificato: Stephen23
il 1 Dic 2019
You should read the MATLAB documentation, which states "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. The preferred method is to store related data in a single array." (this advice applies to accessing as well as creating):
There are alternatives to eval which are much more efficient that what you are doing now. If you explained how you are getting all of those variables into the workspace, we could help you to write much better code.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!