function with xmin causes error

15 visualizaciones (últimos 30 días)
Svenja Delle
Svenja Delle el 30 de Mzo. de 2017
Comentada: Svenja Delle el 30 de Mzo. de 2017
I am supposed to create xmin as a function but no matter what I try MatLab always displays:
Error using minfun
Too many input arguments.
My code looks like this:
function xmin=minfun(x)
n=length(x);
xmin=x1;
for k=2:n
if (x(k)<xmin)
xmin=x(k);
end
end
end
I really have no idea where I made a mistake...

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Mzo. de 2017
The problem is in how you execute the function. You need to go to the command line and type in the function name and the input argument. For example,
minfun([pi exp(2) sqrt(5)])
  1 comentario
Svenja Delle
Svenja Delle el 30 de Mzo. de 2017
Oh it's such a stupid mistake. Thank you so much you saved my day. :)

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by