【问题标题】:Matlab animate background and line in same figureMatlab动画背景和同一图中的线条
【发布时间】:2017-05-25 00:36:19
【问题描述】:

我正在尝试同时在动态背景上为线条设置动画,问题是我无法在同一个图中同时更新两者。如果我为背景设置动画,则不会出现线条。 那么问题是为什么?我在不同的位置上尝试过,但没有成功。

如果去掉imagesc的部分,就没有问题,而且线条流动的动画

for k = 1:numel(t)
    decay = rand;
    res = decay * background;
    imagesc(x,y,flip(res));
    hold on
    clearpoints(h);
    clearpoints(p);

    addpoints(p,[l,(cosO(k)],[0,cosO(k)]);
    addpoints(h,[r,(senO(k)],[0,senO(k)]);

    drawnow
    hold off
end

已修复!创建处理程序并在循环内修改 CData:

imh = imagesc(x,y,flip(res));
for ...
    imh.CData = flip(res);

end

【问题讨论】:

  • 使用hold on 调用imagesc,或者省略最后的hold off,或者使用imh=imagesc(...)作为i=1然后@987654329 @ 代表i>1
  • 谢谢,保持开/关策略不起作用,但是创建处理程序并修改它的 CData!
  • @user2999345 请将您的评论转换为答案,否则 OP 可能会这样做。

标签: matlab animation matlab-figure


【解决方案1】:

imagesc 的调用超出了您的计划。您可以通过仅更改imagesc 表示的图像矩阵(作为'CData' 属性)来克服这个问题:

for k = 1:numel(t)
    decay = rand;
    res = decay * background;
    if k == 1
        imh = imagesc(x,y,flip(res));
    else
        imh.CData = flip(res);
        % or: set(imh, 'CData', flip(res) ); % in older MATLAB versions
    ...
end

【讨论】:

    猜你喜欢
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 2012-05-24
    • 2012-09-22
    • 1970-01-01
    • 2017-03-15
    • 2017-10-12
    相关资源
    最近更新 更多