sort cell array in a struct

1 Ansicht (letzte 30 Tage)
Chiara Scarpellini
Chiara Scarpellini am 7 Aug. 2021
Beantwortet: Walter Roberson am 8 Aug. 2021
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 Kommentare
Walter Roberson
Walter Roberson am 7 Aug. 2021
Bearbeitet: Walter Roberson am 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 am 7 Aug. 2021
it works! huge thank you!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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);

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by