Borrar filtros
Borrar filtros

How to sort rows of matrix according ot its amount of Nan?

1 visualización (últimos 30 días)
The matrix is like this: Data =
1 2 NaN 4 NaN
4 NaN 2 NaN 2
7 1 5 NaN 4
9 4 3 7 NaN
row 1 = 2 NaNs, row 2 = 2 NaNs, row 3 = 1 NaN, row 4 = 1 NaN.
and it can be described like this: [2 2 1 1] what can i do if i want to make it like this:
Data =
7 1 5 NaN 4
9 4 3 7 NaN
1 2 NaN 4 NaN
4 NaN 2 NaN 2
row 1 = 1 NaN, row 2 = 1 NaN, row 3 = 2 NaNs, row 4 = 2 NaNs. and it can be described like this: [1 1 2 2]
what to do? thanks before :)

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 24 de Abr. de 2012
[ii ii] = sort(sum(isnan(Data),2))
out = Data(ii,:)
  3 comentarios
Isti
Isti el 7 de Mayo de 2012
what can i do if i want to make a sort in descending way (actually the opponent sort of above)?
thanks before :)
Andrei Bobrov
Andrei Bobrov el 7 de Mayo de 2012
[ii ii] = sort(sum(isnan(Data),2),'descend');
out = Data(ii,:)

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