フィルターのクリア

How can I sort these number?

2 ビュー (過去 30 日間)
Sanjib
Sanjib 2022 年 1 月 4 日
回答済み: DGM 2022 年 1 月 4 日
a=[-4 4 -7 9 -2 -5 3 7] and I want to sort is as b=[ 9 7 -7 -5 4 -4 3 -2],
b=sort([a],'descend','ComparisonMethod','abs') does not work here as it short 7,-7 as -7,7.

採用された回答

DGM
DGM 2022 年 1 月 4 日
Try this
a = [-4 4 -7 9 -2 -5 3 7];
b = sort(a,'descend');
[~,idx] = sort(abs(b),'descend');
b = b(idx)
b = 1×8
9 7 -7 -5 4 -4 3 -2

その他の回答 (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