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: conditional operator
Replies: 27   Last Post: Mar 25, 2013 11:46 AM

Advanced Search

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

Posts: 3
Registered: 4/30/07
conditional operator
Posted: Apr 30, 2007 7:43 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi there fellow MATLABers,

I have recently had the following "problem": I wanted to define a
function such as the sinc function (sin(x)/x), which for x->0
approaches 1, but obviously MATLAB throws a division by zero error.
The solution is simple enough (define the function in an m-file, use
an if-statement, and test for the "offending" input). Done that,
works fine.

Here is my question for the community: ideally I would have liked to
define an anonymous function (sinc = @(x) sin(x)/x;), but that does
not allow the if-statement. In C, I would have used the conditional
operator "?", as in ( (x==0)?1:sin(x)/x ).
I am not aware of MATLAB having such a nice tool; does somebody know
a simple way to achieve the same thing?


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.