function []=cart(l1,time,position,angle1)
cart=figure('color','white');
ax = axes('Parent', cart);
hold(ax, 'on');
axis(ax, 'off', 'equal');
line([-2 2], [0 0], 'color', [0 0 0], 'LineWidth', 2, 'Parent', ax);
title(ax, 'cart plotting', 'Color', [.6 0 0]);
fill_y = [.03 .13 .13 .03];
p1_y = .015;
p2_y = .015;
for i=1:length(time)
fill_x = [position(i)-.1 position(i)-.1 position(i)+.1 position(i)+.1];
p1_x = position(i)-.08;
p2_x = position(i)+.08;
xp1 = position(i) + l1*sin(angle1(i));
yp1 = .08 + l1*cos(angle1(i));
lh_x = [position(i) xp1];
lh_y = [.08 yp1];
if i == 1
fh = fill(fill_x, fill_y , 'r');
p1 = plot(p1_x, p1_y, 'o', 'MarkerFaceColor', 'g',...
'MarkerSize',5 );
p2 = plot(p2_x, p2_y, 'o', 'MarkerFaceColor', 'g',...
'MarkerSize', 5);
lh = line( lh_x, lh_y, 'color', [1 1 0], 'LineWidth', 2);
p3 = plot(xp1, yp1, 'o', 'MarkerFaceColor', 'k', 'MarkerSize', 7);
else
set(fh, 'Vertices', [fill_x(:), fill_y(:)]);
set(p1, 'XData', p1_x);
set(p2, 'XData', p2_x);
set(lh, 'XData', lh_x, 'YData', lh_y);
set(p3, 'XData', xp1, 'YData', yp1);
end
drawnow
pause(.1);
end
end
Best Answer