Structure Array in Matlab

90 Views Asked by At

I have created a structure array in matlab as follows:

clc;
clear all;
close all;
field1 = 'relation';  value1 = {'Brother','Sister','Grandfather'};
field2 = 'name';  value2 = {'Samuel', 'Giorgia','Alex'};
field3 = 'state';  value3 = {'LA', 'NY', 'CA' };
field4 = 'age';  value4 = [26 19 68];

family_structure = struct(field1,value1,field2,value2,field3,value3,field4,value4);

Now I need to retrieve the minimum age by using min(), however i can manually do this. Moreover,If I convert this structure array into cell array as

family_cell=struct2cell(family_structure);

How can I use the min() function to retrieve the same.

NB: I have figured it out for both structure array and cell

Input:

clc;
clear all;
close all;
family.relation= 'Brother';
family.name='Turing';
family.state = 'NY';
family.age=28
family(2).relation= 'Sister';
family(2).name='Giorgea';
family(2).state = 'LA';
family(2).age=19
family(3).relation= 'Grandfather';
family(3).name='Fiegenbaum';
family(3).state = 'CA';
family(3).age=68

Command For Structure Array:

min([family.age]')

Output: 19

Command For Cell:

family_cell=struct2cell(family);
f=cell2mat(family_cell(4,:)');
min([f(2,:)])

Output: 19