Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 183584

Submitted on 31 Dec 2012 by Alfonso Nieto-Castanon

Correct

27Size
This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%% Test the example
a.n=1;
a.name='a';
b.n=3;
b.name='b';
c.n=2;
c.name='c';
array = [a b c]
% solution based on the first numeric field :
array_sorted = [a c b]
assert(isequal(your_fcn_name(array),array_sorted))
array =
1x3 struct array with fields:
    n
    name
array_sorted =
1x3 struct array with fields:
    n
    name
ans =
1x3 struct array with fields:
    n
    name
2
Pass
 
%% Another test
s1.age = 33
s1.name = 'aurelien'
s2.age = 25
s2.name = 'jeanpierre'
array = [s1 s2 ]
% solution based on the first numeric field :
array_sorted = [s2 s1]
assert(isequal(your_fcn_name(array),array_sorted))
s1 =
    age: 33
s1 =
     age: 33
    name: 'aurelien'
s2 =
    age: 25
s2 =
     age: 25
    name: 'jeanpierre'
array =
1x2 struct array with fields:
    age
    name
array_sorted =
1x2 struct array with fields:
    age
    name
ans =
1x2 struct array with fields:
    age
    name