1

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

  • 2
    If you figured out the answer, you can post an answer and accept it so that the question is marked as answered. By the way, this type of Matlab programming question is a better fit for stackoverflow. – littleO Oct 15 '16 at 00:08
  • Okay, next time I will take care of it. – Amar Kaswan Oct 15 '16 at 01:54

0 Answers0