hi everybody i want to make animation using matlab but frames are plotted to gether on the same figure

1 vue (au cours des 30 derniers jours)
% cart plotting
function []=cart(l1,time,position,angle1) %cart(pendulum length,time vector,position vector,angle vector)
close all;
cart=figure('color','white');
hold on;
axis off; axis equal
line([-2 2],[0 0],'color',[0 0 0],'LineWidth',2);
title('cart plotting','Color',[.6 0 0]);
for i=1:length(time)
fill([position(i)-.1 position(i)-.1 position(i)+.1 position(i)+.1],[.03 .13 .13 .03],'r');
plot(position(i)-.08,.015,'o','MarkerFaceColor','g',...
'MarkerSize',5);
plot(position(i)+.08,.015,'o','MarkerFaceColor','g',...
'MarkerSize',5);
% pendulum (1) co-ordinates ::
xp1=position(i)+l1*sin(angle1(i));
yp1=.08+l1*cos(angle1(i));
line([position(i) xp1],[.08 yp1],'color',[1 1 0],'LineWidth',2);
plot(xp1,yp1,'o','MarkerFaceColor','k','MarkerSize',7);
drawnow
pause(.1);
end
end

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Mar 2017
% cart plotting
function []=cart(l1,time,position,angle1) %cart(pendulum length,time vector,position vector,angle vector)
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;
% pendulum (1) co-ordinates ::
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

Plus de réponses (0)

Catégories

En savoir plus sur Language Fundamentals dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by