Not enough input arguments
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Paul Hoffrichter
on 4 Dec 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.
0 Comments
See Also
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!