converting values from conditional to single equation

1 次查看(过去 30 天)
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 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by