sort cell array in a struct

4 views (last 30 days)
I need to sort the vector Codes and I need the values of vector Discharge to be ordinated according to it. I tried the function sortrows but in this case it doesn't work since in soe cases I'm not working with scalars.
  6 Comments
Walter Roberson
Walter Roberson on 7 Aug 2021
Edited: Walter Roberson on 8 Aug 2021
[Name_Code.Codes, Cidx] = cellfun(@sort,Name_Code.Codes,"UniformOutput",false);
Name_Code.Discharge = cellfun(@(d,idx)d(idx), Name_Code.Discharge, Cidx);
Chiara Scarpellini
Chiara Scarpellini on 7 Aug 2021
it works! huge thank you!

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 8 Aug 2021
(Moving down from comment)
[Name_Code.Codes, Cidx] = cellfun(@sort,Name_Code.Codes,"UniformOutput",false);
Name_Code.Discharge = cellfun(@(d,idx)d(idx), Name_Code.Discharge, Cidx);

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices 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!