Not enough input arguments error with fplot

5 visualizaciones (últimos 30 días)
Ece Balkan
Ece Balkan el 7 de Jul. de 2016
Comentada: Ece Balkan el 7 de Jul. de 2016
This is my plot function, and i would like to plot the data and a function with given time steps, but i get the error attached below.Any help would be appreciated. Thanks!
"Error using PlotFunction>@(t,x)((x(1)*t)/(x(2)+t)) (line 17) Not enough input arguments."
function PlotFunction(x,data)
t = [0.200,0.200,0.222,0.222,0.286,0.286,0.400,0.400,0.667,0.667,2.00,2.00];
figure
plot(t,data,'ro');
title('Measurement data')
xlabel('Time')
ylabel('Measured values')
hold on
for i=1:12
fplot(@(t,x)((x(1)*t)/(x(2)+t)),[t(i) t(i+1)]);
end
hold off
grid on
end

Respuesta aceptada

Stephen23
Stephen23 el 7 de Jul. de 2016
Editada: Stephen23 el 7 de Jul. de 2016
The function that you are providing to fplot is the problem.
You should read the fplot documentation. There it clearly describes what syntaxes and inputs are allowed. Bascially it boils down to these two:
  • fplot(f,...) plots input f for x...
  • fplot(xt,yt) plots xt = x(t) and yt = y(t) ....
Note that the first is a function of one variable x. The second is two functions of one variable t. You are providing a function of two variables, x and t. This is not supported by fplot.
Those ranges do not make any sense: e.g. for the first loop iteration the range will be t = [0.200,0.200], thus having a width of exactly zero. Why are you trying to plot a graph with width zero ?
Also note that using t for both the vector variable and within the anonymous function is bad coding style: is this is mistake, should they be the same variable, or is there some confusion about how to define an anonymous function to use t ? The code makes it impossible to know. Good code is written with comments, which makes it easier to understand what should be happening.
  1 comentario
Ece Balkan
Ece Balkan el 7 de Jul. de 2016
Thanks for quick reply. I solved it as below.
function PlotFunction(x,data)
t = [0.200,0.200,0.222,0.222,0.286,0.286,0.400,0.400,0.667,0.667,2.00,2.00];
figure
a=x(1);
b=x(2);
h=@(t)((a*t)/(b+t));
fplot(h,[t(1) t(12)],'bo');
hold on
plot(t,data,'ro');
title('Measurement data')
xlabel('Time')
ylabel('Measured values')
grid on
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by