Borrar filtros
Borrar filtros

A query relating a function with 3 input arguments.

1 visualización (últimos 30 días)
Alek Poudel
Alek Poudel el 12 de Ag. de 2021
Comentada: Alek Poudel el 12 de Ag. de 2021
My code is:
function i = Three_inputsFunction (x,y,z)
if x>y>z || y>x>z
x+y
elseif x<y<z || x<z<y
y+z
else
x+z
end
end
>> Three_inputsFunction (-18,-3,-6)
ans =
-21
Query : Why is the answer '-21' and not '-9'?

Respuesta aceptada

Stephen23
Stephen23 el 12 de Ag. de 2021
Editada: Stephen23 el 12 de Ag. de 2021
"Why is the answer '-21' and not '-9'?"
Because this code
x>y>z
(x>y)>z
which (because true==1 and false==0) is equivalent to either of these
1>z
0>z
You need this instead:
x>y && y>z
Also note that you do not define the function output i.
  6 comentarios
Stephen23
Stephen23 el 12 de Ag. de 2021
@Alek Poudel: you can also show your thanks by accepting my answer :)
Alek Poudel
Alek Poudel el 12 de Ag. de 2021
ohh yeah, done! didn't know about that before. Cheers!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with 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