How to sort the column of matrix according to amount of NaN for each column?

2 visualizaciones (últimos 30 días)
Isti el 21 de Abr. de 2012
In simple case, I have the matrix like this:
NaN 1 4 6 NaN
9 NaN 6 1 2
NaN 3 2 8 3
7 NaN 1 9 3
7 1 8 2 4
and from the matrix we can see the amount of the NaNs: column 1= 2, column 2= 2, column 3= 0, column 4= 0, column 5= 1,
so i want to sort the columns in the matrix according to their NaNs and become like this:
4 6 NaN NaN 1
6 1 2 9 NaN
2 8 3 NaN 3
1 9 3 7 NaN
8 2 4 7 1
May somebody help me with the code? Thanks before :')
0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

Respuesta aceptada

Rick Rosson el 21 de Abr. de 2012
n = sum(isnan(A));
1 comentarioMostrar NingunoOcultar Ninguno
Isti el 21 de Abr. de 2012
Thanks for this helping answer. it's produce the amount of the NaN from each column.
And i still have the problem with exchange the column according to that amount.
Is there any code to sort the columns?

Iniciar sesión para comentar.

Más respuestas (1)

Rick Rosson el 21 de Abr. de 2012
n = sum(isnan(A));
B = transpose([ n ; A ]);
C = sortrows(B);
R = transpose(C(:,2:end));
1 comentarioMostrar NingunoOcultar Ninguno
Isti el 21 de Abr. de 2012
it works. thank you very much for your help :)

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by