Why does my plot hold old data with linkdata?

4 views (last 30 days)
Javier
Javier on 27 Sep 2018
Edited: Walter Roberson on 27 Sep 2018
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!

Answers (1)

Walter Roberson
Walter Roberson on 27 Sep 2018
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 Comments
Javier
Javier on 27 Sep 2018
Edited: Javier on 27 Sep 2018
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 on 27 Sep 2018
Edited: Walter Roberson on 27 Sep 2018
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;

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!