Clear Filters
Clear Filters

Which are the alternative codes of heaviside() function?

20 views (last 30 days)
Which are the alternative codes of heaviside() function?

Accepted Answer

GandaBerunda on 16 Jun 2022
Hi Tufan,
Instead of using the heaviside() function, you can define your own function with a simple if elseif ladder. If the parameter is less than 0, you can return 0, at equal to 0, return 0.5 and greater than 0 return 1.
Hope it helps.
Sam Chak
Sam Chak on 16 Jun 2022
Sure @Tufan can learn to write a custom function. However, the heaviside() function also uses the if-else conditional statement. If you can write a conditional-free simple code that works similarly as the Heaviside function, then it will benefit the community.
GandaBerunda on 18 Jun 2022
One simple approach without if else which I can think of is:
where out is the result, and x is the input

Sign in to comment.

More Answers (0)


Find more on Event Functions in Help Center and File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!