如何控制同一个fig​ure中两个画图句柄​的图形同步更新?。

5 vues (au cours des 30 derniers jours)
新锦江娱乐官方网站【微8785092】
我在一个figure里,同时使用两个plot的句柄画图形,并用drawnow函数实现动画显示。
我希望两个句柄能够同时更新图形,而不要一前一后显示图形。
demo如下:
close all;
figure(1);
hold on;
grid on;
axis([0, 15, 0, 15]);
h1 = plot(NaN, NaN, 'Color', 'r');
h2 = plot(NaN, NaN, 'Color', 'b');
for i = 1:1:10
    set(h1, 'XData', i, 'YData', i, 'Marker', 's');
    pause(0.5);  % 此处是为了说明这个问题而加的调试代码,实际代码是由于大量的运算导致在此处占用了太多时间
    set(h2, 'XData', i, 'YData', i + 1, 'Marker', 's');
   
    drawnow;
    pause(0.1);
end
如上代码所示,我希望h1和h2的图形,都在drawnow处才更新。
但实际在figure中看到的图形显示效果是,set h1数据时,h1的图形就更新了,因此h1的图形更新比h2快。但我希望他两同时更新。
代码中的pause(0.5)是为了说明这个问题而加的调试代码,实际代码此处是由于大量的运算导致在此处占用了太多时间

Réponse acceptée

新锦江娱乐客服网址【微8785092】
把 h1 的数据保存为临时变量 等 h2 的计算结果出来了, 一起画就行了

Plus de réponses (0)

Catégories

En savoir plus sur 图形性能 dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!