From: Antonio Trujillo-Ortiz on
Hi all,

Suppose a matrix A with Nan's, such as:

A=[1 2 Nan 4 5
Nan 8 NaN 3 6
7 10 7 3 4
3 NaN 6 NaN 8
NaN 8 NaN NaN NaN];

and we are interesting to arrange it according to the number of NaN's in rows to have,

B=[NaN 8 NaN NaN NaN
Nan 8 NaN 3 6
3 NaN 6 NaN 8
1 2 Nan 4 5
7 10 7 3 4];

As you can see. Row 1 with 4 NaN's, row 2 with 2, row 3 with 2, row 4 with 1, and row 5 (last) without NaN's.

I would apprciate any hint on this.

Thx
From: us on
"Antonio Trujillo-Ortiz" <atrujo(a)uabc.edu.mx> wrote in message <i0k076$q50$1(a)fred.mathworks.com>...
> Hi all,
>
> Suppose a matrix A with Nan's, such as:
>
> A=[1 2 Nan 4 5
> Nan 8 NaN 3 6
> 7 10 7 3 4
> 3 NaN 6 NaN 8
> NaN 8 NaN NaN NaN];
>
> and we are interesting to arrange it according to the number of NaN's in rows to have,
>
> B=[NaN 8 NaN NaN NaN
> Nan 8 NaN 3 6
> 3 NaN 6 NaN 8
> 1 2 Nan 4 5
> 7 10 7 3 4];
>
> As you can see. Row 1 with 4 NaN's, row 2 with 2, row 3 with 2, row 4 with 1, and row 5 (last) without NaN's.
>
> I would apprciate any hint on this.
>
> Thx

one of the many solutions

m=[
1 2 NaN 4 5
NaN 8 NaN 3 6
7 10 7 3 4
3 NaN 6 NaN 8
NaN 8 NaN NaN NaN
];
[sx,sx]=sort(sum(isnan(m),2),'descend');
r=m(sx,:)
%{
% r =
NaN 8 NaN NaN NaN
NaN 8 NaN 3 6
3 NaN 6 NaN 8
1 2 NaN 4 5
7 10 7 3 4
%}

us
From: Antonio Trujillo-Ortiz on
Hi us,

Thanks for your valuable help.