Sort an array of structures - MATLAB Cody - MATLAB Central

Problem 689. Sort an array of structures

Difficulty:Rate

You need to sort an array of structures based upon a numeric first field:

For example :

a.n=1;
a.name='a';
b.n=3;
b.name='b';
c.n=2;
c.name='c';
array = [a b c]

This array of 3 structures is not sorted yet since:

>> array(2)

shows: ans =

       n: 3
    name: 'b'

The aim is to have for this example the output array such as :

>> array(1)
ans = 
         n: 1
      name: 'a'
>> array(2)
ans = 
         n: 2
      name: 'c'
>> array(3)
ans = 
         n: 3
      name: 'b'

The input of this problem is an array of structures. .

Solution Stats

41.61% Correct | 58.39% Incorrect
Last Solution submitted on May 12, 2024

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers48

Suggested Problems

More from this Author30

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!