COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### remove row if contains NaN

• Email
• Follow

```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

See related articles to this posting

```"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

```"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

```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=m(~isnan(m(:,2)),:)
%{
%    m =
1    97
1    47
2    13
2    97
2    47
%}

us
```
 0

```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 (7455) 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 (7455) 7/26/2012 1:03:52 AM

7 Replies
2419 Views

Similar Articles

12/10/2013 11:07:43 PM
page loaded in 42653 ms. (0)

Similar Artilces:

removing texture
I have a part with texture applied on many features and faces. Is it any fast way to remove all texture from everything(features, faces etc)? Is there a Texture Property manager that shows all textures on that part Thanks You could probably write a macro that would do it. "Alex" <alexkuzn.remove@pacbell.net.remove> wrote in message news:020Ac.63\$SE.59@newssvr25.news.prodigy.com... > I have a part with texture applied on many features and faces. > Is it any fast way to remove all texture from everything(features, faces etc)? > Is there a Texture Property manager tha...

Merging rows
Hello, Client has requested that I merge certain rows of data in this table CREATE TABLE `answer` ( `id` int(11) NOT NULL auto_increment, `applicant` varchar(255) REFERENCES applicant(id), `question` int(11) REFERENCES question(id), `answer` text NOT NULL, PRIMARY KEY (`id`) ) The relationship between each question and applicant is unique. What I need to do is look up each applicant's answers to question 3 and question 4 and merge them into the answer for question 3. I was feebly trying things like: UPDATE testAnswer SET answer = CONCAT( (SELECT answer AS start FRO...

Removing text
I have an image that I created with a white background, a design, and two small lines of black text. I now wish I had put the text somewhere else and made it gray instead of black. If I use the selection tool around the text, and then "cut" the text out, it's replacing it with white and it LOOKS perfectly fine. But I just need some reassurance that this method won't cause problems when the image is printed on ceramic. Can I be sure that there will be no trace of the text in its original location? Will it look like it's been edited? Or would it be better to re...

Remove watermark ?
http://www.aaip.biz/images/paintings/CEZANNE_VASE_DELPHI.jpg Image with a #&! watermark like a hexagonal pattern all over it. Selecting by color not removes all, blurring is loss on sharpness : If one sharps again later, the pattern is coming back... thx, L lisztfr wrote: > http://www.aaip.biz/images/paintings/CEZANNE_VASE_DELPHI.jpg > > Image with a #&! watermark like a hexagonal pattern all over it. > Selecting by color not removes all, blurring is loss on sharpness : If > one sharps again later, the pattern is coming back... thx, This is not a watermark. It's...

removing buffers
When I open a file, Emacs automatically open a scratch buffer and a message buffer. Can I set some option to get rid of them? TIA, Michele Simionato Michele Simionato wrote: > When I open a file, Emacs automatically open a scratch buffer and a > message buffer. Can I set some option to get rid of them? > > TIA, > > Michele Simionato Not really. Scratch is a default. You can set an option so scratch doesn't have that opening message. Just have Emacs automatically load up your work files at startup and pretend scratch doesn't exist. Or,...

containers of iterators to each other
I want to accomplish something as close to the following as possible: typedef std::vector<B::iterator> A; typedef std::vector<A::iterator> B; The only safe way I can think of to solve this problem is using an extra memory allocation to hide the iterators in subclasses, and storing a smart-pointer to the base in each vector. Obviously, this is sub-optimal. Can anyone think of an efficient approach at getting to work was is being attempted above? joshua lehrer factset research NYSE:FDS [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.mode...

How to remove a serial interface
Hello I'm trying to remove a serial interface in a cisco 3640 but I dont know how. I tryed just removing it but my adsl configuration stopped working. A no interface is not working. Thank you all. Pablo. if the interface is physically installed it will appear in your Cfg. If this is the case, goto config mode and enter the "interface serial 0/0" and the "shutdown". If you have a Cfg, were a serial interface appears that you have just removed from the router. Then it will be there untill you reload the router. At boot time if will remove the Cfg entries from running ...

Remove Dust From Pic
To All: From my review of the on-line help in PSP 7.04, this procedure is not obvious to me. I have pic with a "dust spot", probably from dust on the lens. The dust spot is easy to select with the "magic wand" tool. It is on a uniform background (blue sky). How to I replace the dust spot with blue sky? Thank you, Steve Tanja Saily wrote: > Kiri wrote: >> I'd use the clone tool for that. > > The scratch remover tool might work as well. :-) Tanja: Unfortunately, the scratch removal tool does not work. That was my first choice. Steve Yes but...

removing from set
std::set<Stuff>::iterator current_item( stuff_set.begin() ); while ( current_item != stuff_set.end() ) { if ( is_bad( *item ) ) { std::set<Stuff>::iterator previous_item( --current_item ); stuff_set.erase( ++current_item ); current_item = previous_item; } ++current_item; } Is this the best way I can structure this? I hate writing code like this :( -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] Alfons wrote: > std::set<Stuff>::iterator current_item( stuff_set.begin() ); ...

Not all macro quotes removed?
I thought all macro quotes are removed before the SAS statement processor goes to work. If so, this is a puzzle. Is it a SAS bug? %let a=A; %let b=B; * This creates one data set AB as you would expect; data &a&b; x=1; run; * Now put macro quotes around A; %let a=%quote(A); * The same code now creates TWO(!!!) data sets, A and B; data &a&b; x=1; run; * But this use of regular SAS variables appears normal; data _null_; y="&A&B"; put y=; leng = length(y); put leng=; run; * Writes the following to the log: y=AB leng=2 ; ...

Hiding a row in CListCtrl
This has been asked on a few different posts, but I hope I can add a different spin to the question. I need to hide a row in CListCtrl rather than delete/insert a row. I realize hiding a row isn't supported, but has anybody successfully simulated a hidden row, such as setting the height of a row to zero? Thanks, Jared <jared_hagel@hotmail.com> wrote in message news:0bbe5295-efca-41c8-b454-0a3e55b18dcb@v67g2000hse.googlegroups.com... > This has been asked on a few different posts, but I hope I can add a > different spin to the question. > > I need to hide...

Removing focus from uicontrol
Hi all, here what i want to do i want to remove focus from a pushbutton...and activate a function using the space bar directly afterwards i have tried to move focus to the figure window using uicontrol(hObject) with no success any help wold be greatly appriciated Colin > i want to remove focus from a pushbutton...and activate a function > using the space bar directly afterwards To remove focus from an object, you must specify a new focus object. You can specify a 'neutral' one (eg, the figure itself). this is done by: >> set(gcf, 'CurrentObject',gcf); to a...

Remove some columns from a matrix
Hello, A=rand (200, 450); I would like to remove these columns (20, 36, 50:60, 71, 89) from 'A' . Should I use following command line to do this function? I wrote 50:60 since I need also to remove columns from 50 to 60. A(:,20&36&50:60&&71&89)=[]; Thanks, Jerry "Jerry " <jerrycholo@gmail.com> wrote in message news:kfipqu\$o9t\$1@newscl01ah.mathworks.com... > Hello, > > A=rand (200, 450); > > I would like to remove these columns (20, 36, 50:60, 71, 89) from 'A' . > Should I use following command li...

Don't even know if this is a javascrip thing...but how do I remove the underline from hyperlinks? "Ed" <eyoung@ncsa.uiuc.edu> wrote in message news:0kefb.187\$fm2.70622@vixen.cso.uiuc.edu... > Don't even know if this is a javascrip thing...but how do I remove the > underline from hyperlinks? > It 's a css thing: <style type="text/css"> a {text-decoration:none} a:hover{text-decoration:underline} </style> The second line makes links underlined onmouseover only. HTH Ivo Ed wrote: > Don't even know if this is a javascrip th...

Dear All Since the glibc library has removed the pthreads in favour of fork processes which is better for multi core processors glibc or gib from gnome website? (which has pthreads) thanks in advance Neil Morris wrote: > Since the glibc library has removed the pthreads in favour of fork Source? Rui Maciel Neil Morris wrote: > Since the glibc library has removed the pthreads in favour of fork > processes which is better for multi core processors glibc or gib from > gnome website? (which has pthreads) The "linuxthreads" library has been removed from glibc beca...

Unable to Remove App
I installed Opera web browser on Tiger a few weeks ago as a trial, i.e. unregistered. Didn't like it so removed with CleanAPP. I noticed the other day that in the Services Menu I still get an Opera option and amazingly if I click on any of the Opera options, I get Opera opening again!! I've used Spotlight (set to search everything) and removed everything releating to Opera. Gone into preferences and removed any Opera items. STILL the services menu option remains and still opens Opera when clicked? Help - how do I remove? Thanks -- Clive Life is not measured by the number of...

Removing *all* uniboard from a domain
Hi, Is it possible to move all CPU boards from one SF12K domain to another? Is it required that each domain have at least one board assigned to it? Supak Supak Lailert wrote: > Hi, > > Is it possible to move all CPU boards from one SF12K domain to another? Is > it required that each domain have at least one board assigned to it? > > Supak > > You can remove all CPU/mem boards from any domain as long as you shutdown Solaris in that domain first. Elias ...

Which rows cause exception
Oracle 9.2.05 SE In a stored procedure I have code like this: INSERT INTO DPRS_WELL (PRODUCTION_MONTH,UWI,....) SELECT ad_prod_date,UWI,... FROM DPRS_WELL_LOAD WHERE PRODUCTION_MONTH = add_months(ad_prod_date,-1); EXCEPTION WHEN DUP_VAL_ON_INDEX THEN RAISE_APPLICATION_ERROR(-20001,'Duplicate UWI', true); WHEN VALUE_ERROR THEN RAISE_APPLICATION_ERROR(-20002,'Value error', true); Is there any way I can determine in the exception block which row(s) caused the exception? -- Terry Dykstra Terry Dykstra wrote: > Oracle 9.2.05 SE > > In a stored pr...

tablelist row configuration
I wonder if this is possible. I have a tablelist with 2 columns. One is an entry (user names) and the other is text (user comments). When the text column has more lines than one, the display automatically adjusts to show the full text. This is nice but it has a side effect. The entry widget becomes centered vertically. Is there a way to have it fixed at the top of the row? Thanks! DrS Am 09.03.2012 16:57, schrieb DrS: > I wonder if this is possible. I have a tablelist with 2 columns. One is > an entry (user names) and the other is text (user comments). When the > text co...

Removing files in directtories
Almost there... I've included line 7 as I'd like to be able to remove files from a directory using code blocks. Commented it out for now until I can work out how it's done. Suggestions appreciated. #!/usr/bin/ruby -w def back_up backdir = ENV["HOME"] + "/foo/" puts "about to backup some files and tar them into ~/foo" puts "listing data in ~/foo" ...