Converting Struct field to array

1,513 ビュー (過去 30 日間)
Gabriel Stanley
Gabriel Stanley 2021 年 6 月 9 日
コメント済み: Matt Weber 2022 年 10 月 11 日
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.


James Tursa
James Tursa 2021 年 6 月 9 日
Does this do what you want?
MyMatrix = vertcat(MyStruct.Field);
  1 件のコメント
Gabriel Stanley
Gabriel Stanley 2021 年 6 月 9 日
It does indeed. Thanks!


その他の回答 (1 件)

David Hill
David Hill 2021 年 6 月 9 日
  2 件のコメント
Matt Weber
Matt Weber 2022 年 10 月 11 日
David Hill's solution worked for me, the other one did not. My context was a struct with just one field level.



Find more on Structures in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by