Converting Struct field to array
Ältere Kommentare anzeigen
I have an n-value structure array with multiple fields, and want to extract a specific field (all values thereof are (1x4) single arrays) into a nx4 array.
MyMatrix = [MyStruct(:).FieldC];
concatenates the values of the field, giving me a 1x(n*4) array. There's probably a way to reshape that, but I would appreicate a more direct solution as I'm doing this in the command window on an as-needed basis, rather than via a script.
Akzeptierte Antwort
Weitere Antworten (1)
David Hill
am 9 Jun. 2021
MyMatrix=cell2mat(struct2cell(MyStruct));
2 Kommentare
Gabriel Stanley
am 9 Jun. 2021
Matt Weber
am 11 Okt. 2022
David Hill's solution worked for me, the other one did not. My context was a struct with just one field level.
Kategorien
Mehr zu Structures finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!