How to sort arrays with respect to one of the element in it

1 vue (au cours des 30 derniers jours)
PRANAY DISHAN
PRANAY DISHAN le 14 Fév 2018
Commenté : PRANAY DISHAN le 14 Fév 2018
Hello everyone, I have
Harmony=7x1 struct with two fields(solution & cost)
NewHarmony=3x1 struct with two fields(solution & cost)
I have combined Harmony and Newharmony and created NHS.
NHS=10x1 struct with two fields(solution & cost)
Now I need to sort the NHS with respect to the costs developed and eliminate the last three elements which will give new set of Harmony with optimised Cost values.
Please help me on this, Thank u

Réponse acceptée

Walter Roberson
Walter Roberson le 14 Fév 2018
[~, idx] = sort([NHS.cost]);
NHS = NHS(idx(1:end-3));

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by