Which are the alternative codes of heaviside() function?

조회 수: 19 (최근 30일)
Tufan
Tufan 2016년 6월 7일
댓글: GandaBerunda 2022년 6월 18일
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에서 Event Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by