How to use piecewise in Octave

Is there an intuitive way of using the piecewise function in Octave?

May you kindly provide a simple example for the absolute value function?

y=x if x>=0    
y=-x if x<0

Upvotes: 0

Views: 2224

Answers (1)

James
James

Reputation: 398

Could you just write your own piecewise function? Something like:

function [y] = my_piecewise(x)
    y = x
    if x< 0
       y = -x
    endif
end function

Upvotes: 3

Related Questions