Which are the alternative codes of heaviside() function?

12 次查看(过去 30 天)
Which are the alternative codes of heaviside() function?

采纳的回答

GandaBerunda
GandaBerunda 2022-6-16
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.
  2 个评论
Sam Chak
Sam Chak 2022-6-16
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
GandaBerunda 2022-6-18
One simple approach without if else which I can think of is:
out=(x>0)+0.5*(x==0)
where out is the result, and x is the input

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Install Products 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by