Not enough input arguments

13 ビュー (過去 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 Center および File ExchangeEvent Functions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by