Why does my plot hold old data with linkdata?

4 次查看(过去 30 天)
Hello,
I am using linkdata to update automatically the some plots. However, I am facing the issue that the hold on command seems to affect the data being depicted in that the old data remains in the plot an it's not deleted. I have a forloop that is calling the function below
function showDifferences(org,toCheck,signalsNames,err)
linkdata on
p1=subplot(2,1,1);
grid on;hold on;
plot(org,'-.o','MarkerSize',2.5);
plot(toCheck,'-.or','MarkerSize',2.5);
legend(['Original:' signalsNames{1}] ,['Calculated:' signalsNames{2}]);
title(['Original:' signalsNames{1} ' vs Calculated:' signalsNames{2}]);
ylabel('Signal Amplitude')
hold off;
p2=subplot(2,1,2);
plot(abs(toCheck-org),'-*','MarkerSize',2.5);
legend(['Original:' signalsNames{1} ' - Calculated:' signalsNames{2}]);
title(['Error Original:' signalsNames{1} ' vs Calculated:' signalsNames{2} '.Absolute RMS Error:' num2str(err) ]);
ylabel('Difference');
hold off;
linkaxes([p1,p2],'x');
end
I get this
Why the old data is not being removed?
Thanks in advance!

回答(1 个)

Walter Roberson
Walter Roberson 2018-9-27
This appears to have nothing to do with data linking.
Your first plot sequence starts by manipulating the axes grid setting. That does not affect which graphics objects are present. You then hold on, which says that all new graphics objects are to be added to the ones already present in the axes. You plot some things and turn hold off. Next loop cycle, you change grid settings which does not affect the graphics objects, then you turn hold on, the new plot calls add to the previous ones for the axes, and so on.
The second axes though, never has hold on in effect, so the plot() call erases the current axes content each time that plot() call is reached.
hold on only applies to the current axes, not to all axes.
  2 个评论
Javier
Javier 2018-9-27
编辑:Javier 2018-9-27
Then how should I use the hold on to make it work? Should I have to added it just per plot? Otherwise I cannot plot two graphs on the subplot(2,1,1)
Walter Roberson
Walter Roberson 2018-9-27
编辑:Walter Roberson 2018-9-27
In the code
grid on;hold on;
plot(org,'-.o','MarkerSize',2.5);
Exchange those two lines.
plot(org,'-.o','MarkerSize',2.5);
grid on;hold on;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by