separate matrices out of struct
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Rightia Rollmann
il 11 Gen 2017
Commentato: Stephen23
il 11 Gen 2017
I have a struct having matrices of B1, B2, and B3. I want to make three separate matrices out of them available in the Workspace automatically with the help of a loop. How?
S = struct('B1',[1 2;3 4],'B2', [5 6; 7 8], 'B3', [9 10; 11 12] )
1 Commento
Stephen23
il 11 Gen 2017
"I want to make three separate matrices out of them available in the Workspace automatically with the help of a loop"
Here is why that would be a very bad idea:
Risposta accettata
Jos (10584)
il 11 Gen 2017
Why? Apparently the three matrices are related. Keeping them in a single struct shows this relationship. If you need to access one of them you can easily do this using assignment operations
X = S.B1
or dynamically
k = 2
field = sprintf('B%d',k)
X = S.(field)
0 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Structures 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!