views:

36

answers:

1
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
+2  A: 

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

alt text

Amro
I should point out that I followed this animated GIF example to create the above figure: http://www.mathworks.com/matlabcentral/fileexchange/21944-animated-gif
Amro

related questions