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!