sort cell array in a struct

3 visualizzazioni (ultimi 30 giorni)
Chiara Scarpellini
Chiara Scarpellini il 7 Ago 2021
Risposto: Walter Roberson il 8 Ago 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 Commenti
Walter Roberson
Walter Roberson il 7 Ago 2021
Modificato: Walter Roberson il 8 Ago 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 il 7 Ago 2021
it works! huge thank you!

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 8 Ago 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);

Più risposte (0)

Categorie

Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by