Why does my plot hold old data with linkdata?

조회 수: 4 (최근 30일)
Javier
Javier 2018년 9월 27일
편집: Walter Roberson 2018년 9월 27일
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