How do I output a vectors in the order for example, z1, z2,z3,z4,z5....after having a 1 x 5 cell array go through a for loop?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
George Vuong
am 13 Aug. 2015
Bearbeitet: Stephen23
am 19 Jun. 2019
Hello,
Lets say I have a cell array Z, and it contains the following. This is just a simple example.
Z = {1,4,13,2,6}
How can I write a for loop so that it will output five vectors in numerical order, like Z1,Z2,Z3,Z4,Z5 such that each vector contains the values in each cell in Z. The following output would be ideal.
Z1 = 1
Z2 = 4
Z3 = 13
Z4 = 2
Z5 = 6
I am using 2015a btw. Any help would be appreciated. Thanks!
0 Kommentare
Akzeptierte Antwort
Star Strider
am 13 Aug. 2015
Recent versions support cells automatically doing the same as the deal function:
Z = {1,4,13,2,6};
[Z1,Z2,Z3,Z4,Z5] = Z{:}
5 Kommentare
Weitere Antworten (1)
Stephen23
am 13 Aug. 2015
Bearbeitet: Stephen23
am 19 Jun. 2019
2 Kommentare
Stephen23
am 14 Aug. 2015
Bearbeitet: Stephen23
am 14 Aug. 2015
My pleasure. I hope that those links were interesting to read. Basically when you consider doing this:
X1 = ...
X2 = ...
X3 = ...
you can see that the 1, 2, 3, etc, are really just indices... so then why not avoid all of the slowness, bugginess and obfuscation of using eval and just make them actual indices:
X(1) = ...
X(2) = ...
X(3) = ...
Much faster, easier to debug, easier to search for in your files, and MATLAB Editor provides pop-ups with the values, instance highlighting, etc, etc.
You will not regret learning how to program without eval!
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!