How can I add a point to an animation?

1 次查看(过去 30 天)
I want to add the point b3 to the animation so that every in the end every b3 is in the animation
r =0;
s= 2;
z = [15, 0; 7, 10; 3, 4; 3, 6];
axis(gca, 'equal');
axis([0 16 0 20]);
k = 1;
for t = r:0.01:s
...
b3 = (1 - lambda ) * b2(1,:) + lambda * b2(2, :);
i
crank1 = line(z(:,1), z(:,2));
crank2 = line(b1(:,1), b1(:,2));
crank3 = line(b2(:,1), b2(:,2));
crank4 = line(b3(1), b3(2));
pause(0.1);
delete(crank1);
delete(crank2);
delete(crank3);
delete(crank4);
end
x = b3;
end
  1 个评论
KSSV
KSSV 2018-6-27
Most of the variables are not defined..what is b3? it's dimensions?

请先登录,再进行评论。

回答(2 个)

Sayyed Ahmad
Sayyed Ahmad 2018-6-27
you need to add in your code
hold on
otherweise you create every time a new graph and your point is not exist anymore.

Sammit Jain
Sammit Jain 2018-6-27
Hi, since the exact context of the code isn't clear, I'm making the following assumptions:
  • You're probably trying to simulate/animate some form of a crank-slider mechanism.
  • You're opening a figure window and plotting these lines continuously. These coordinates are updated in a for loop
  • b3 is one point represented as [x,y]. (From the code it looks like it's a weighted average based on lambda)
In this case, your question boils down to representing a single point in a plot window. Now since you're animating, a simple way for you to do this is to use the 'viscircles' command. This will allow you to make an approximate representation of a point with a tiny circle.
Check out the documentation for viscircles
With this you can make a visual representation of the ‘point’ by centering a circle on the x,y coordinates for the point (which are stored in b3), with a small radius. The circle will be drawn using the afore-mentioned viscircles command. You will have to choose a radius according to the scale of your animation.
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by