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!
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!