Dear Mathworks users ^^
I have a matrix of 800x2
1 NaN
1 NaN
1 NaN
1 NaN
1 97
1 47
1 NaN
1 NaN
2 NaN
2 NaN
2 NaN
2 13
2 97
2 47
2 NaN
2 NaN
...... continued
I want to :
if row contains NAN, remove row completely so i end up with :
1 97
1 47
2 13
2 97
2 47
What function can i use? I've tried to 'find' the Nan's but it appears blank:
[r,c,v]=find(x==nan)
Thanks you!
Kind regards,
Natalie ^^
|
|
0
|
|
|
|
Reply
|
Natalie
|
7/16/2010 2:32:05 PM |
|
"Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i1pqh4$pmj$1@fred.mathworks.com>...
> Dear Mathworks users ^^
>
> I have a matrix of 800x2
> 1 NaN
> 1 NaN
> 1 NaN
> 1 NaN
> I want to :
>
> if row contains NAN, remove row completely so i end up with :
> 1 97
> 1 47
> 2 13
> 2 97
> 2 47
A = [1 2;3 4; nan 5];
A(~any(isnan(A),2),:)
|
|
2
|
|
|
|
Reply
|
Sean
|
7/16/2010 2:42:08 PM
|
|
"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i1pr40$470$1@fred.mathworks.com>...
> "Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i1pqh4$pmj$1@fred.mathworks.com>...
> > Dear Mathworks users ^^
> >
> > I have a matrix of 800x2
> > 1 NaN
> > 1 NaN
> > 1 NaN
> > 1 NaN
>
> > I want to :
> >
> > if row contains NAN, remove row completely so i end up with :
> > 1 97
> > 1 47
> > 2 13
> > 2 97
> > 2 47
>
> A = [1 2;3 4; nan 5];
> A(~any(isnan(A),2),:)
Oh wow! thats a really good code!! :D so short ^^ THANKS SO MUCH!
thank youuuuuuuuuuuuu!!!
|
|
0
|
|
|
|
Reply
|
Natalie
|
7/16/2010 3:52:06 PM
|
|
On Jul 16, 8:52=A0am, "Natalie Sin Hwee " <sin.n...@imperial.ac.uk>
wrote:
> "Sean " <sean.dewol...@nospamplease.umit.maine.edu> wrote in message <i1p=
r40$47...@fred.mathworks.com>...
> > "Natalie Sin Hwee " <sin.n...@imperial.ac.uk> wrote in message <i1pqh4$=
pm...@fred.mathworks.com>...
> > > Dear Mathworks users ^^
>
> > > I have a matrix of 800x2
> > > 1 =A0 =A0 NaN
> > > 1 =A0 =A0 NaN
> > > 1 =A0 =A0 NaN
> > > 1 =A0 =A0 NaN
>
> > > I want to :
>
> > > if row contains NAN, remove row completely so i end up with :
> > > 1 =A0 =A0 97
> > > 1 =A0 =A0 47
> > > 2 =A0 =A0 13
> > > 2 =A0 =A0 97
> > > 2 =A0 =A0 47
>
> > A =3D [1 2;3 4; nan 5];
> > A(~any(isnan(A),2),:)
>
> Oh wow! thats a really good code!! :D so short ^^ THANKS SO MUCH!
> thank youuuuuuuuuuuuu!!!
Another solution:
x =3D [nan nan;1 nan; 1 1; 1 2; 2 nan; 2 1; nan 2]
x(logical(sum(x~=3Dx,2)),:)=3D[]
%%%%%%%%%%%%%%%%
x =3D
1 1
1 2
2 1
-Nathan
|
|
0
|
|
|
|
Reply
|
ngreco32 (530)
|
7/16/2010 7:21:08 PM
|
|
"Natalie Sin Hwee " <sin.ng09@imperial.ac.uk> wrote in message <i1pqh4$pmj$1@fred.mathworks.com>...
> Dear Mathworks users ^^
>
> I have a matrix of 800x2
> 1 NaN
> 1 NaN
> 1 NaN
> 1 NaN
> 1 97
> 1 47
> 1 NaN
> 1 NaN
> 2 NaN
> 2 NaN
> 2 NaN
> 2 13
> 2 97
> 2 47
> 2 NaN
> 2 NaN
>
>
> ..... continued
>
>
> I want to :
>
> if row contains NAN, remove row completely so i end up with :
> 1 97
> 1 47
> 2 13
> 2 97
> 2 47
>
> What function can i use? I've tried to 'find' the Nan's but it appears blank:
> [r,c,v]=find(x==nan)
>
> Thanks you!
>
> Kind regards,
> Natalie ^^
one of the many solutions
m=[ % <- your data...
];
m=m(~isnan(m(:,2)),:)
%{
% m =
1 97
1 47
2 13
2 97
2 47
%}
us
|
|
0
|
|
|
|
Reply
|
us
|
7/16/2010 7:37:04 PM
|
|
These solutions only appear to work when selecting a particular column. This removes any row that has a NaN within any column:
%Matrix A
A(find(sum(isnan(A),2)==0),:)
|
|
0
|
|
|
|
Reply
|
smfret2 (3)
|
7/25/2012 9:18:23 PM
|
|
On 7/25/2012 4:18 PM, John wrote:
....
> This removes any row that has a NaN within any column:
> %Matrix A
> A(find(sum(isnan(A),2)==0),:)
That _leaves_ rows w/ NaN's...the "==" should be "~="
Somewhat simpler is
A(any(isnan(A),2),:)=[];
--
|
|
1
|
|
|
|
Reply
|
none1568 (6639)
|
7/25/2012 10:00:24 PM
|
|
On 7/25/2012 5:00 PM, dpb wrote:
> On 7/25/2012 4:18 PM, John wrote:
> ...
>
>> This removes any row that has a NaN within any column:
>> %Matrix A
>> A(find(sum(isnan(A),2)==0),:)
>
> That _leaves_ rows w/ NaN's...the "==" should be "~="
>
> Somewhat simpler is
>
> A(any(isnan(A),2),:)=[];
....
Or, if your intent was B=A(...) where B has no NaN then your logic
direction is correct just complement isnan() or use isfinite() (assuming
that it isn't desired to Inf in the result as well as NaN, of course)
B=A(~any(isnan(A),2),:)
or
B=A(all(isfinite(x),2),:)
--
|
|
0
|
|
|
|
Reply
|
none1568 (6639)
|
7/26/2012 1:03:52 AM
|
|
|
7 Replies
1934 Views
(page loaded in 0.112 seconds)
|