Borrar filtros
Borrar filtros

How can I sort these number?

2 visualizaciones (últimos 30 días)
Sanjib
Sanjib el 4 de En. de 2022
Respondida: DGM el 4 de En. de 2022
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.

Respuesta aceptada

DGM
DGM el 4 de En. de 2022
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

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by