对于算法的P
次迭代,我在-constant-图像上有T
个点的像素位置,所以locations = [T x 2*P] double
。
现在我想创建一个动画,在其中绘制图像,然后绘制点,暂停N
秒并将其位置更新到下一步。我不知道是否有标准的方法可以遵循。我想我需要这样的东西:
figure;
imshow(img);
hold on;
for t=1:T
anim = updatePlot(locations(t,:), anim); % ?
end
如何实现此updatePlot
功能?
感谢您的帮助!
答案 0 :(得分:1)
你可以通过几种不同的方式做到这一点。第一种方法是为绘制的点提供一个句柄,以便您可以在下一次迭代之前删除它们:
figure
imshow(img);
hold on;
for t = 1:T
% delete the previous points plotted (skip t = 1 since they won't exist)
if t > 1
delete(hPoints);
end
hPoints = plot(xLocations(t,:),yLocations(t,:),'.');
getframe;
pause(N);
end
(我不确定如何解析每行的位置以分隔x和y组件,所以我只是使用xLocations
和yLocations
来表示这些值。)
第二种方法是在每次迭代时重新绘制整个图像:
figure
for t = 1:T
clf;
imshow(img);
hold on;
plot(xLocations(t,:),yLocations(t,:),'.');
getframe;
pause(N);
end
请注意,imshow
可能有自己的getframe
效果,因此您在绘制点之前会看到图像闪烁 - 如果发生这种情况,只需从imshow
切换到{ {1}}。