Assign elements in multidimensional struct to 2D array
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Collin
am 14 Sep. 2022
Kommentiert: Collin
am 14 Sep. 2022
I have a 1xN multidimenstional struct, where each entry contains data of size 1xM.
for ii=1:5, C(ii).pts = rand(1,3); end
I would like an elegant way to get an NxM array as a concatinated output of the struct. Is this possible?
% Returns of size 1xMN
[C.pts]
% Will not run but get something like this of size NxM
[c.pts']
Relevant questions:
https://www.mathworks.com/matlabcentral/answers/7155-elegant-way-to-extract-part-of-a-structure-as-an-array
2 Kommentare
Akzeptierte Antwort
James Tursa
am 14 Sep. 2022
Bearbeitet: James Tursa
am 14 Sep. 2022
You can use the vercat( ) function to force the comma-separated-list generated by C.pts to stack vertically:
for ii=1:5, C(ii).pts = rand(1,3); end
vertcat(C.pts)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures 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!