필터 지우기
필터 지우기

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 CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by