extract all values of a specific field from a struct array

If i have an array like

 A = [
   struct( 'uid', 165215, 'type', 8, 'data', [0,3,16388,17523,12,225,225,280,242,223,256,266,261,226,225,259,210]);
   struct( 'uid', 196334, 'type', 2, 'data', [0,96,398,359,350,4,416,406,450,39]);
   % ...
   struct( 'uid', 173261, 'type', 8, 'data', [0,13,5081,5658,48]);
 ];

Is there a way to extract all 'type' members to a own Nx1 Matrix? something like:

b = A(:).type; % this only returns "b = 8"

or even more complex apply logical operators on members and get a vector of answers:

I = A(:).type==1;

this throws:

error: binary operator '==' not implemented for 'cs-list' by 'scalar' operations

Answers


An indexing operation like the one you used returns a cs-list (called comma separated variables in matlab). To convert it to a array or cell array, put the corresponding brackets around it:

 b = [A(:).type] ;

The line above creates an array, in case you need a cell in other cases use {} instead. You will need it to index data.


Need Your Help

How to migrate hyperloglog key to azure redis

azure redis azure-redis-cache hyperloglog

I am trying to migrate an redis hyperloglog key from one server to azure redis service using the MIGRATE command, but as far as i know MIGRATE doesn't support moving key to a redis server which req...

Highcharts - how to properly update series[0].data and yAxis title of a VUMeter?

javascript jquery highcharts

I am preparing a VU Meter graph in Highcharts to display an array of values.