Not enough input arguments

조회 수: 8 (최근 30일)
sara syeda
sara syeda 2020년 12월 3일
답변: Paul Hoffrichter 2020년 12월 4일
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

답변 (1개)

Paul Hoffrichter
Paul Hoffrichter 2020년 12월 4일
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.

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by