Sorting a structure using Matlab2018

1 view (last 30 days)
Hi
I want to sort this structure in descensind order using MATLAB 2018:
ten.cat=[7,2,4,1].
I used the following commands but it is still not sorted:
pp_1=ten;
TT = struct2table(pp_1) % convert to tables
gg=sortrows(TT,'cat') % sort
sortedpp_1 = table2struct(gg) % convert the table back to structure.
please, help
  3 Comments

Sign in to comment.

Accepted Answer

Jan
Jan on 29 May 2019
ten.cat = [7,2,4,1];
ten.cat = sort(ten.cat)

More Answers (1)

Simon Mählkvist
Simon Mählkvist on 29 May 2019
Edited: Simon Mählkvist on 29 May 2019
Hi,
Adjusting:
ten.cat=[7,2,4,1]
to:
ten.cat=[7;2;4;1]
gives what I think is the sought after results.

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!