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

1 回表示 (過去 30 日間)
PRANAY DISHAN
PRANAY DISHAN 2018 年 2 月 14 日
コメント済み: PRANAY DISHAN 2018 年 2 月 14 日
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

採用された回答

Walter Roberson
Walter Roberson 2018 年 2 月 14 日
[~, idx] = sort([NHS.cost]);
NHS = NHS(idx(1:end-3));
  1 件のコメント
PRANAY DISHAN
PRANAY DISHAN 2018 年 2 月 14 日
Thank you so much sir.. it worked. :-)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by