Clear Filters
Clear Filters

Sorting a structure using Matlab2018

1 view (last 30 days)
I want to sort this structure in descensind order using MATLAB 2018:[7,2,4,1].
I used the following commands but it is still not sorted:
TT = struct2table(pp_1) % convert to tables
gg=sortrows(TT,'cat') % sort
sortedpp_1 = table2struct(gg) % convert the table back to structure.
please, help
Guillaume on 29 May 2019
@Jan, this should go as an answer as I see no way of improving on that with the information given.
@shamsuddeen, there's never any need to convert a structure to anything in order to operate on it. Certainly, converting a structure into a table and back is a complete waste of time for your purpose. In this case, the fact that ten is a structure is completely irrelevant anyway, you're not sorting a structure, but just one field of a scalar structure which is the same as any non-structure variable.

Sign in to comment.

Accepted Answer

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

More Answers (1)

Simon Mählkvist
Simon Mählkvist on 29 May 2019
Edited: Simon Mählkvist on 29 May 2019
gives what I think is the sought after results.


Find more on Guidance, Navigation, and Control (GNC) 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!