Combine multiple matrix variables into a structure?
Afficher commentaires plus anciens
I currently have 180 matrix variables (1336 x 4) that I would like to make into a structure to make it easier to work with. In the end I want to be able to plot all of this data in the same way on separate plots or subplots.
What is the best way to combine the matrices? I am able to create a structure using 'whos' and then add on a 'data' field of zeros to put the final data in but how would I transcribe all of the variable data into the structure? The variables are not concurrently named so I am struggling to get a for loop to work.
3 commentaires
Stephen23
le 4 Sep 2018
@Kirsty Alsop: the most important question is how did you get those 180 matrices into the workspace? Presumably you did not sit and write them all out by hand, in which case they must have been imported somehow, or generated in a loop somehow... and that is the correct location to fix this problem! If you tell us how these variables first got into your workspace, then we can show you better ways to design your code, so that your data handling is simpler, more efficient, and less buggy.
Magically accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
Kirsty Alsop
le 4 Sep 2018
Walter Roberson
le 4 Sep 2018
The best approach would be to not get into this situation, to store the information in a structured manner instead of in separate variables.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!