Thread Subject: NaN handle

Subject: NaN handle

From: Luca

Date: 11 Jun, 2006 15:14:36

Message: 1 of 10

Hello, I need help for handle NaN values in data arrays. I desire to
consider all NaN the same values ( like in the function “
isequalwithequalnans”) . How can I do? Someone can help me? Thanks

Subject: NaN handle

From: verm25@hotmail.com

Date: 11 Jun, 2006 13:30:25

Message: 2 of 10

You want to reimplement isequalwithequalnans()? Why?
Just for kicks I tried. My version looks like:

ans=isempty(find(~((a==b) | (a~=b & isnan(a) & isnan(b)))));

This asks each pair of elements of a and b are equal and if not then
whether
they are both NaN. In either case the corresponding logical value of
one is
produced. Then we ask whether there are any zeros.

Luca wrote:
> Hello, I need help for handle NaN values in data arrays. I desire to
> consider all NaN the same values ( like in the function "
> isequalwithequalnans") . How can I do? Someone can help me? Thanks

Subject: NaN handle 2

From: Luca

Date: 12 Jun, 2006 04:06:59

Message: 3 of 10

I have to made a program that erase NaN from a data array.
The problem if that every NaN is considered a single value and is
impossible to erase it with a if loop.

Thanks.
 
verm25 wrote:
>
>
> You want to reimplement isequalwithequalnans()? Why?
> Just for kicks I tried. My version looks like:
>
> ans=isempty(find(~((a==b) | (a~=b & isnan(a) & isnan(b)))));
>
> This asks each pair of elements of a and b are equal and if not
> then
> whether
> they are both NaN. In either case the corresponding logical value
> of
> one is
> produced. Then we ask whether there are any zeros.
>
> Luca wrote:
>> Hello, I need help for handle NaN values in data arrays. I
desire
> to
>> consider all NaN the same values ( like in the function "
>> isequalwithequalnans") . How can I do? Someone can help me?
> Thanks
>
>

Subject: NaN handle 2

From: Michael Salloker

Date: 12 Jun, 2006 12:11:29

Message: 4 of 10

Luca schrieb:
> I have to made a program that erase NaN from a data array.
> The problem if that every NaN is considered a single value and is
> impossible to erase it with a if loop.
>
> Thanks.
>

How about

x(~isnan(x))

But be careful, thsi will only work for vectors!

Michael

Subject: NaN handle

From: Luca

Date: 12 Jun, 2006 11:45:30

Message: 5 of 10

Thanks but this create a vector erasing the NaN values.
You know how consider two NaN equal?

Thanks.
 
Michael Salloker wrote:
>
>
> Luca schrieb:
>> I have to made a program that erase NaN from a data array.
>> The problem if that every NaN is considered a single value and
is
>> impossible to erase it with a if loop.
>>
>> Thanks.
>>
>
> How about
>
> x(~isnan(x))
>
> But be careful, thsi will only work for vectors!
>
> Michael
>

Subject: NaN handle

From: Jerome

Date: 12 Jun, 2006 11:47:57

Message: 6 of 10

Luca wrote:

> Thanks but this create a vector erasing the NaN values.
> You know how consider two NaN equal?

Hi,

it could be easier if you post a small example !

Jérôme

Subject: NaN handle

From: Steve Amphlett

Date: 12 Jun, 2006 12:49:47

Message: 7 of 10

Jérôme wrote:
>
>
> Luca wrote:
>
>> Thanks but this create a vector erasing the NaN values.
>> You know how consider two NaN equal?
>
> Hi,
>
> it could be easier if you post a small example !

Or just type in the whole homework question verbatim.

Subject: NaN handle 4

From: Luca

Date: 13 Jun, 2006 12:47:45

Message: 8 of 10

Good idea: this is the program:

clear all, close all, clc
p_min_b = [0 0 0 0 0 0 0 180.08 0 0 0 179.87 0 0 0 0 0 0 179.57 0
...
      
0 0 179.41 0 0 0 0 179.56 0 0 0 179.6 0 179.7 0 0 0 178.84 0 178.66...

        0 0 178.6 0 0 178.53 0 0 178.43 0];
% I divide the row arrey in 20 + 20 + 10 data points because is esier
to see it
% I wont to erase the values higher than 179.41 (data 179.56, 179.6,
179.7) that correspond to
% p_min_b colomn 28, 32, 34

non_zero=find(p_min_b) % this find the colomn values different to 0

%the answer is

% non_zero =
%
% 8 12 19 23 28 32 34 38 40 43 46
  49

% now I say to take this colomn values and compare with the values
before.
% If it's larger put NaN.
long_non_zero=length(non_zero) % this give the length of the non_zero
row vector.

% this is usefull for the for cicle for stop it in the end.

for i=2:long_non_zero
    if p_min_b(non_zero(i)) >= p_min_b(non_zero(i-1))
        p_min_b(non_zero(i))= NaN
    end
end

%the answer is

% p_min_b=[0 0 0 0 0 0 0 180.08 0 0 0 179.87 0 0 0 0 0 0 179.57 0 ...
%
0 0 179.41 0 0 0 0 NaN 0 0 0 179.6 0 NaN 0 0 0 178.84 0 178.66 ...
% 0 0 178.6 0 0 178.53 0 0 178.43 0]

% like you can see don't erase the value 179.6
% If I chose 0 it will erase every number
% If I chose to put the same value of the step before and after erase
it
% whit an other for loop it will have the same problem. It will not
erase
% the second value

 
Steve Amphlett wrote:
>
>
> Jérôme wrote:
>>
>>
>> Luca wrote:
>>
>>> Thanks but this create a vector erasing the NaN values.
>>> You know how consider two NaN equal?
>>
>> Hi,
>>
>> it could be easier if you post a small example !
>
> Or just type in the whole homework question verbatim.

Subject: NaN handle 4

From: verm25@hotmail.com

Date: 13 Jun, 2006 18:08:33

Message: 9 of 10

Instead of NaN, use Inf.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
If you ever post asking for help again, please bear in mind that you
need to
reduce your code so as to be easily readable. I have no idea of the
structure of p_min_b from what you have posted. In the future, try to
limit your
example code to 3x3 matrices and format the text so it is easy to read.
Also, when you say "circle" I think you mean "loop". If so, learn
programming
first. Just a bit of correct terminology goes a long way.

Luca wrote:
> Good idea: this is the program:
>
> clear all, close all, clc
> p_min_b =3D [0 0 0 0 0 0 0 180.08 0 0 0 179.87 0 0 0 0 0 0 179.57 0
> ...
>
> 0 0 179.41 0 0 0 0 179.56 0 0 0 179.6 0 179.7 0 0 0 178.84 0 178.66...
>
> 0 0 178.6 0 0 178.53 0 0 178.43 0];
> % I divide the row arrey in 20 + 20 + 10 data points because is esier
> to see it
> % I wont to erase the values higher than 179.41 (data 179.56, 179.6,
> 179.7) that correspond to
> % p_min_b colomn 28, 32, 34
>
> non_zero=3Dfind(p_min_b) % this find the colomn values different to 0
>
> %the answer is
>
> % non_zero =3D
> %
> % 8 12 19 23 28 32 34 38 40 43 46
> 49
>
> % now I say to take this colomn values and compare with the values
> before.
> % If it's larger put NaN.
> long_non_zero=3Dlength(non_zero) % this give the length of the non_zero
> row vector.
>
> % this is usefull for the for cicle for stop it in the end.
>
> for i=3D2:long_non_zero
> if p_min_b(non_zero(i)) >=3D p_min_b(non_zero(i-1))
> p_min_b(non_zero(i))=3D NaN
> end
> end
>
> %the answer is
>
> % p_min_b=3D[0 0 0 0 0 0 0 180.08 0 0 0 179.87 0 0 0 0 0 0 179.57 0 ...
> %
> 0 0 179.41 0 0 0 0 NaN 0 0 0 179.6 0 NaN 0 0 0 178.84 0 178.66 ...
> % 0 0 178.6 0 0 178.53 0 0 178.43 0]
>
> % like you can see don't erase the value 179.6
> % If I chose 0 it will erase every number
> % If I chose to put the same value of the step before and after erase
> it
> % whit an other for loop it will have the same problem. It will not
> erase
> % the second value
>
>
> Steve Amphlett wrote:
> >
> >
> > J=E9r=F4me wrote:
> >>
> >>
> >> Luca wrote:
> >>
> >>> Thanks but this create a vector erasing the NaN values.
> >>> You know how consider two NaN equal?
> >>
> >> Hi,
> >>
> >> it could be easier if you post a small example !
> >
> > Or just type in the whole homework question verbatim.

Subject: NaN handle 5

From: Luca

Date: 14 Jun, 2006 05:31:27

Message: 10 of 10

Thanks for the advices; is it my first program.

Luca

verm25 wrote:
>
>
> Instead of NaN, use Inf.
>
> ===========================================================
> If you ever post asking for help again, please bear in mind that
> you
> need to
> reduce your code so as to be easily readable. I have no idea of the
> structure of p_min_b from what you have posted. In the future, try
> to
> limit your
> example code to 3x3 matrices and format the text so it is easy to
> read.
> Also, when you say "circle" I think you mean "loop". If so, learn
> programming
> first. Just a bit of correct terminology goes a long way.
>
> Luca wrote:
>> Good idea: this is the program:
>>
>> clear all, close all, clc
>> p_min_b =
[0 0 0 0 0 0 0 180.08 0 0 0 179.87 0 0 0 0 0 0 179.57 0
>> ...
>>
>>
>
0 0 179.41 0 0 0 0 179.56 0 0 0 179.6 0 179.7 0 0 0 178.84 0 178.66.
> ..
>>
>> 0 0 178.6 0 0 178.53 0 0 178.43 0];
>> % I divide the row arrey in 20 + 20 + 10 data points because is
> esier
>> to see it
>> % I wont to erase the values higher than 179.41 (data 179.56,
> 179.6,
>> 179.7) that correspond to
>> % p_min_b colomn 28, 32, 34
>>
>> non_zero=find(p_min_b) % this find the colomn values different
to
> 0
>>
>> %the answer is
>>
>> % non_zero =
>> %
>> % 8 12 19 23 28 32 34 38 40 43 46
>> 49
>>
>> % now I say to take this colomn values and compare with the
> values
>> before.
>> % If it's larger put NaN.
>> long_non_zero=length(non_zero) % this give the length of the
> non_zero
>> row vector.
>>
>> % this is usefull for the for cicle for stop it in the end.
>>
>> for i=2:long_non_zero
>> if p_min_b(non_zero(i)) >= p_min_b(non_zero(i-1))
>> p_min_b(non_zero(i))= NaN
>> end
>> end
>>
>> %the answer is
>>
>> %
> p_min_b=[0 0 0 0 0 0 0 180.08 0 0 0 179.87 0 0 0 0 0 0 179.57 0 ...
>> %
>>
> 0 0 179.41 0 0 0 0 NaN 0 0 0 179.6 0 NaN 0 0 0 178.84 0 178.66 ...
>> % 0 0 178.6 0 0 178.53 0 0 178.43 0]
>>
>> % like you can see don't erase the value 179.6
>> % If I chose 0 it will erase every number
>> % If I chose to put the same value of the step before and after
> erase
>> it
>> % whit an other for loop it will have the same problem. It will
> not
>> erase
>> % the second value
>>
>>
>> Steve Amphlett wrote:
>> >
>> >
>> > Jérôme wrote:
>> >>
>> >>
>> >> Luca wrote:
>> >>
>> >>> Thanks but this create a vector erasing the NaN
values.
>> >>> You know how consider two NaN equal?
>> >>
>> >> Hi,
>> >>
>> >> it could be easier if you post a small example !
>> >
>> > Or just type in the whole homework question verbatim.
>
>

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com