Search code examples
arraysmatlabmatlab-struct

MATLAB: collect from array of structs


The output of eg >>w = whos; returns an array of structs. I would like to construct an array whose elements are the scalars from a particular field name in each struct.

The most obvious way of doing this doesn't return an array as I want, but each answer separately.

>> w(1:2).bytes
ans =
    64
ans =
   128

I could do it with a loop, but was wondering if there's a nicer way.


Solution

  • Put square brackets around the expression, i.e.

    [w(1:2).bytes]