情节未重置

时间:2014-04-01 08:34:21

标签: matlab plot matlab-figure

我需要你的帮助。我的程序读取一个M-File,这是一个录制的视频。 要显示每个图像,我使用“imagesc”,因为图像保存为200x200矩阵,标准化值范围为0到1.

阅读完每张图片后,我会做一些微积分。结果应显示为图像的叠加(一个点和一个线)。使用下面的代码,这将在循环的第一次迭代中按预期工作。

在所有进一步的迭代中,图像被重绘(这是正确的),但点和线不会被清除。

如何在显示新图像时清除图表。 我用“hold”命令尝试了几种变体。但没有成功。

其他问题(不重要): 是否可以用“set”(特别是Point)交换下面的“plot”命令?

我的程序包含多个Axes Elements,我将其剪切以保持示例简单。这意味着我的UI使用“plot”命令非常慢,所以我试图用“set”加速它。

效果很好,但我不确定是否可以用“set”显示一个简单的Point。

提前致谢。

function work()
  h_figure = figure('Name','MainFig');
  hImage.ax = axes('Units', 'Pixels','Position', [50 375 200 200]);

  imagesc('Parent',hImage.ax,'CData',zeros(200));
  hImage.axc = get(gca, 'Children');

  hProfileLeft.ax = axes('Position', [50 200 200 100]);
  hProfileLeft.pl = plot(hProfileLeft.ax, 1:200); 

  for(frame = obj.Startframe:obj.Endframe)
    imgIntens= obj.video.A.intens(:,:,frame);
    ProfileResult = doSomeCalc(someArgs); 

    set(hImage.axc, 'CData', imgIntens); % Show Image(200x200 double)

    hold(hImage.ax, 'on'); % Using hold so that plot is overlayed

    plot(ProfileResult.peaks.x, ProfileResult.peaks.y,'Parent',hImage.ax); % Simple Point
    plot(ProfileResult.corridor.left, 1:200, 'Parent',hImage.ax); % Line

    set(hProfileLeft.pl,'YData', ProfileResult.trace); % Draw data to different axes
    hold(hImage.ax, 'off');
  end

end

1 个答案:

答案 0 :(得分:0)

我遇到了同样烦人的行为。对我来说,结论是手动调用cla

使用line代替情节,它有更多的选项(特别好,你可以自己标记线条),并且在调用时不会删除图表,也会返回句柄。获得句柄后,您可以单独删除它们。