MATLAB Answers

Converting Struct field to array

106 views (last 30 days)
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.

Accepted Answer

James Tursa
James Tursa on 9 Jun 2021
Does this do what you want?
MyMatrix = vertcat(MyStruct.Field);

More Answers (1)

David Hill
David Hill on 9 Jun 2021
  1 Comment
Gabriel Stanley
Gabriel Stanley on 9 Jun 2021
Editing my original post to the following effect: there are multiple field in the structure array, and I'm only looking to extract 1 of them to an array.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!

Translated by