Borrar filtros
Borrar filtros

converting values from conditional to single equation

2 visualizaciones (últimos 30 días)
Ali Najem
Ali Najem el 15 de Dic. de 2020
Comentada: Ali Najem el 16 de Dic. de 2020
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

Respuesta aceptada

Alan Stevens
Alan Stevens el 15 de Dic. de 2020
One possibility
f = x(i)*(x(i)>=0) + 0.2*(exp(x(i)) - 1)*(x(i)<0);

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by