Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: how to distinguish -inf and inf
Replies: 14   Last Post: Nov 1, 2010 5:01 AM

 Messages: [ Previous | Next ]
 Alan Posts: 151 Registered: 7/24/09
Re: how to distinguish -inf and inf
Posted: Oct 12, 2010 6:38 PM

"Nils Tobias " <nils.kraemer@uni-ulm.de> wrote in message <i92n63\$ljq\$1@fred.mathworks.com>...
> Thanks Alan, that's true but sorry I still don't know how to put those pieces together.
>
> I have a vector x = [-inf 2 3 inf]
>
> and isinf(x) tells me [1 0 0 1]
>
> How to get isinf_me(x) that gives me back [-1 0 0 1]
>
> I mean -1 and +1 is not necessary any other positive respectively negative number would do.
>
> Thanks
> -NTK
>
>

> > > Is there any built-in function?
> > >
> > > -NTK

> >
> > >> inf>0
> > ans =
> > 1

> > >> -inf>0
> > ans =
> > 0

You can create these two vectors very easily:

isinf = isinf(x); % [1 0 0 1]
sgn = (x>0)*2-1; % [-1 1 1 1]

And hopefully the rest is obvious. Matlab also has a function called sign() that does essentially the same thing that second calculation does, and probably faster.

Date Subject Author
10/12/10 Nils Tobias
10/12/10 Alan
10/12/10 Nils Tobias
10/12/10 Alan
10/12/10 dpb
10/12/10 dpb
10/12/10 mike zander
10/12/10 dpb
10/13/10 mike zander
10/13/10 Nils Tobias
10/31/10 Nils Tobias
10/31/10 Bruno Luong
11/1/10 Bruno Luong
11/1/10 Nils Tobias
10/13/10 dpb