For Programmers: Free Programming Magazines  


Home > Archive > Matlab > April 2005 > index of NaN value in float vector









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author index of NaN value in float vector
bobrics

2005-04-25, 8:59 pm

hi,
if my a = [1 2 NaN]
how would I detect that one of the values is not assigned?
a(3)==NaN gives 0
a(3)=='NaN' gives 0 0 0

I would like to find it's index or logical array for which 1 would
correspond to location of NaN.
I.E.
[0 0 1] means third element is not assigned.

Thank you

brian

2005-04-25, 8:59 pm

bobrics wrote:
>
>
> hi,
> if my a = [1 2 NaN]
> how would I detect that one of the values is not assigned?
> a(3)==NaN gives 0
> a(3)=='NaN' gives 0 0 0
>
> I would like to find it's index or logical array for which 1 would
> correspond to location of NaN.
> I.E.
> [0 0 1] means third element is not assigned.
>
> Thank you
>
>

isnan(a)
Murphy O'Brien

2005-04-25, 8:59 pm

brian wrote:
>
>
> bobrics wrote:
> would
> isnan(a)


OR the now famous and faster (at least in Matlab 7.0)

>a=[1 2 3 NaN];
>a~=a

ans =
0 0 0 1

Murphy
brian

2005-04-26, 4:06 am

Murphy O'Brien wrote:
>
>
> brian wrote:
1[color=darkred]
>
> OR the now famous and faster (at least in Matlab 7.0)
>
> ans =
> 0 0 0 1
>
> Murphy


neat, did not know that.

thanks
brian
Steve Amphlett

2005-04-26, 9:02 am

bobrics wrote:
>
>
> hi,
> if my a = [1 2 NaN]
> how would I detect that one of the values is not assigned?
> a(3)==NaN gives 0
> a(3)=='NaN' gives 0 0 0


In addition to the answers already given, there was an interesting
thread recently, which dealt with the question of why NaN==NaN gives
0.

Johannes, "NaN" #, 11 Apr 2005 5:35
am </WebX?50@@.ef02438>
bobrics

2005-04-26, 4:04 pm

Thank you guys for the replies...
I'll try to find the thread reagarding NaN not being equal to NaN as
well.

neat indeed...

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com