Not enough input arguments

8 visualizaciones (últimos 30 días)
sara syeda
sara syeda el 3 de Dic. de 2020
Respondida: Paul Hoffrichter el 4 de Dic. de 2020
why wont the following code run and keeps giving me the not input arguments error? the three parameters are passed from a simulink model, all three are set to arrays in the toWorkspace setting.
function drawpendulum(time,theta,x)
% Check if x was passed or not
if nargin==2
% If x was not passed, just set x to a vector of zeros
x = zeros(1,length(theta));
end
% Calculate the time different between subsequent time samples
timediff=[diff(time)];
% Limit the refresh to about 10 per second
skip=ceil(0.1*length(time)/(time(end)-time(1)));
figure(1); clf; hold on;
axis([min(x)-2, max(x)+2, -1.1, 1.1]);
for i=1:skip:length(theta)-1
h1=plot(x(i)+sin(theta(i)), cos(theta(i)), 'o');
h2=line(x(i)+[0 sin(theta(i))], [0 cos(theta(i))]);
pause(timediff(i));
drawnow;
delete(h1); delete(h2);
end
end

Respuestas (1)

Paul Hoffrichter
Paul Hoffrichter el 4 de Dic. de 2020
Cannot speak to your simulink model, but the MATLAB code below runs without error.
time = 1:1/100:1000;
theta = -pi/2:pi/(max(time)):pi/2;
x = 5*sin(theta);
drawpendulum(time,theta,x);
drawpendulum(time,theta);
You can put a check in to determine that you have exactly 2 or 3 input args.

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by