converting values from conditional to single equation

Hi all
I need to convert this if condition to one equation
let's assume we have this if statment
if x>=0
f = x(i);
else
f = 0.2*(exp(x)-1);
end
can I re-write if statment in one equation ?
Any suggestion would be appreciated

 채택된 답변

Alan Stevens
Alan Stevens 2020년 12월 15일
One possibility
f = x(i)*(x(i)>=0) + 0.2*(exp(x(i)) - 1)*(x(i)<0);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

질문:

2020년 12월 15일

댓글:

2020년 12월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by