一个图形上的两条曲线,其中一条不断更新 [英] two curves on one figure with one kept updating

查看:67
本文介绍了一个图形上的两条曲线,其中一条不断更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,这些代码基本上在图中绘制了原始信号x,并迭代地更新了重建的信号rec.

I have following code which basically plot the original signal x on the figure, and updates the reconstructed signal rec iteratively.

plot(x); hold on

err = 100; tol = 0.1; err_vec = [];
while err > tol % iterations
    % Low-pass filter xpg
    REC = fft(rec);
    REC(M+2:N-M) = 0;
    rec = real(ifft(REC)); plot(rec, 'r*');  drawnow

    % Restore the known samples    %
    rec(ks) = y(ks);

    % Error
    err = norm(rec - x)
    err_vec = [err_vec err];
end

我喜欢的是保留图中的x,并且在每次迭代时仅更新rec,这样我可以看到rec正在逐渐接近x.

What I like is to retain x on the figure, and only update rec at each iteartion, such that I can see that rec is gradually approaching x.

但是,使用我当前的代码,尽管保留了x,但是每次迭代中的rec都只是在图中重叠了,这很烦人.我只想显示当前迭代中的rec.

However, with my current code, although x is retained, rec from each iteration simply overlaps on the figure, which is annoying. I'd like to show the rec from only current iteration.

我应该如何更改代码来做到这一点?

How should I change my code to do that?

推荐答案

除了@excaza提出的建议之外,您还可以尝试:

Beside the suggestion proposed by @excaza, you can try:

  • 调用plot函数以指定返回值(handle到绘制的行中
  • 绘制更新的曲线
  • 调用pause以减慢"过程
  • 调用delete删除最后绘制的曲线
  • call the plot function specifying the return value (the handle to the line plotted
  • plot the updated curve
  • call pause in order to "slow` the process
  • call delete to delete the last plotted curve

基于两条通用曲线的可能的实现方式可能是:

A possible implementation, based on two generic curves, could be:

t=0:.01:2*pi;
x=sin(t);
plot(t,x)
hold on
grid on
k=0:.1:1
for i=1:length(k)
   y=sin(t);
   hp=plot(t,y*k(i),'r')
   legend('Target Curve','Approximate curve')   
   pause(.3)
   delete(hp)
end

这篇关于一个图形上的两条曲线,其中一条不断更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆