The Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Alan

Posts: 151
Registered: 7/24/09
Re: how to distinguish -inf and inf
Posted: Oct 12, 2010 6:38 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.