Borrar filtros
Borrar filtros

How to sort out negative and positive values of a vector?

10 visualizaciones (últimos 30 días)
if A= -3 -2 -1 0 1 2 3 i want to sort the negative values and positive values in a separate vector

Respuesta aceptada

madhan ravi
madhan ravi el 10 de Oct. de 2018
Editada: madhan ravi el 10 de Oct. de 2018
A=[ -3 -2 -1 0 1 2 3 ]
Negative_nos = sort(A(A<0))
Positive_nos = sort(A(A>=0))
Will do the trick
  2 comentarios
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar el 10 de Oct. de 2018
what sould i do i wanrt to sort only first two values and last three values separately?
madhan ravi
madhan ravi el 10 de Oct. de 2018
Editada: madhan ravi el 10 de Oct. de 2018
sort(A(1:2)) %first two
sort(A(end-2:end)) %last three
give a vote if you find it useful

Iniciar sesión para comentar.

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