为多个椭圆设置动画

发布于 2024-09-08 05:53:46 字数 716 浏览 2 评论 0原文

sRMatTemp = [SENSORRANGE];
sRMat = repmat(sRMatTemp, size(obj.landmarks.sensed(:,1), 1));
ellipse(((2*pi*sRMat)/(360/obj.landmarks.sensed(:,4))), obj.landmarks.sensed(:,5) , obj.landmarks.sensed(:,3), obj.landmarks.apparentPositionsST(:,1), obj.landmarks.apparentPositionsST(:,2));

上面的代码工作正常......一次。问题是我需要让它动起来。每次我绘制椭圆时,它们都会停留在我的屏幕上,并且图表立即变得不可读。

上面的代码也可以很好地工作,可以为散点图设置动画。有没有办法可以以某种方式将其与省略号一起使用?

我正在使用 Mathworks 社区网站上的 ellipse.m。

fig=figure;
axes('NextPlot','add');
set(fig, 'name', 'Animated Graph')
l.st=scatter([0],[0],'g.');
set(l.st,'XData',obj.landmarks.apparentPositionsST(:,1),'YData',obj.landmarks.apparentPositionsST(:,2));
drawnow
sRMatTemp = [SENSORRANGE];
sRMat = repmat(sRMatTemp, size(obj.landmarks.sensed(:,1), 1));
ellipse(((2*pi*sRMat)/(360/obj.landmarks.sensed(:,4))), obj.landmarks.sensed(:,5) , obj.landmarks.sensed(:,3), obj.landmarks.apparentPositionsST(:,1), obj.landmarks.apparentPositionsST(:,2));

The above code works fine... ONCE. The problem is I need to animate it. Every time I plot the ellipses, they stay on my screen and the graph becomes unreadable instantly.

This is the code above that works fine as well, to animate a scatter plot. Is there a way I can use this with ellipses somehow?

I'm using ellipse.m that's on the Mathworks community site.

fig=figure;
axes('NextPlot','add');
set(fig, 'name', 'Animated Graph')
l.st=scatter([0],[0],'g.');
set(l.st,'XData',obj.landmarks.apparentPositionsST(:,1),'YData',obj.landmarks.apparentPositionsST(:,2));
drawnow

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒的傷心 2024-09-15 05:53:47

您需要将EraseMode属性设置为xor,以便当您更新其X/Y数据时,它将删除其旧位置然后重新绘制。请务必阅读此动画指南

我写了一个简单的例子来说明动画椭圆。我正在使用上一个问题中的函数 calculateEllipse.m这里就这样。

step = linspace(50,200,100);

figure
hAx = axes('XLim',[-250 250], 'YLim',[-250 250], ...
    'Drawmode','fast', 'NextPlot','add');
axis(hAx, 'equal')

p = calculateEllipse(0, 0, step(1), step(end), step(1));
hLine = line('XData',p(:,1), 'YData',p(:,2), 'EraseMode','xor',  ...
    'Color','r', 'LineWidth',3);

for i=1:numel(step)
    p = calculateEllipse(0, 0, step(i), step(numel(step)-i+1), step(i));
    set(hLine,'XData',p(:,1), 'YData',p(:,2))  %# update X/Y data
    pause(.05)                                 %# slow down animation
    drawnow                                    %# force refresh
    if ~ishandle(hLine), return; end           %# in case you close the figure
end

animated_ellipse

You need to set the EraseMode property to xor so that when you update its X/Y data, it will delete its old location then redraw. Make sure you read this animation guide.

I wrote a simple example to illustrate an animated ellipse. I am using the function calculateEllipse.m from a previous question here on SO.

step = linspace(50,200,100);

figure
hAx = axes('XLim',[-250 250], 'YLim',[-250 250], ...
    'Drawmode','fast', 'NextPlot','add');
axis(hAx, 'equal')

p = calculateEllipse(0, 0, step(1), step(end), step(1));
hLine = line('XData',p(:,1), 'YData',p(:,2), 'EraseMode','xor',  ...
    'Color','r', 'LineWidth',3);

for i=1:numel(step)
    p = calculateEllipse(0, 0, step(i), step(numel(step)-i+1), step(i));
    set(hLine,'XData',p(:,1), 'YData',p(:,2))  %# update X/Y data
    pause(.05)                                 %# slow down animation
    drawnow                                    %# force refresh
    if ~ishandle(hLine), return; end           %# in case you close the figure
end

animated_ellipse

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文