필터 지우기
필터 지우기

How to freeze the range of y-axis on an axes on gui?

조회 수: 55 (최근 30일)
MatlabNewbie01232015
MatlabNewbie01232015 2015년 1월 25일
편집: Dario Mangoni 2018년 12월 11일
I am trying to plot the time audio signal using plot(handles.axes1, x) which works fine. The problem is that I cannot make the make the range of a y-axis fix at [-1 1]. I try to set the YLim to be [-1, 1], and YLimMode to be 'manual' both in property windows settings using gui and also in callcall back

답변 (3개)

Dario Mangoni
Dario Mangoni 2018년 12월 11일
편집: Dario Mangoni 2018년 12월 11일
Currently (at R2018b) this operation is made easy through 'axis manual' command.
figure;
hold on;
plot(1,1,'+')
plot(2,2,'+')
axis manual
plot(50,50,'+')
The point (50,50) is not in view because axis limits has been retained.
See axis documentation for more options.

Matt J
Matt J 2015년 8월 28일
편집: Matt J 2015년 8월 28일
It is not enough to set YLimMode to 'manual'. You need to apply "hold on" as Geoff mentioned. However, you can still use CLA to clear the plot between re-renderings, like in the example below.
axis([0,11,-1,1]);
h=gca;
hold on
h.YLimMode='manual';
for i=1:100,
plot(1:10,rand(1,10));
pause(.3);
drawnow
cla
end
hold off

Geoff Hayes
Geoff Hayes 2015년 2월 2일
Try using ylim which will allow you to set the y-axis limits. In your case, you could do something like
ylim(handles.axes1,[-1 1]);
In order to keep these limits, you may need to call
hold(handles.axes1,'on');
so that you return the current properties of the axes before a new plot is added to it.
  댓글 수: 2
MatlabNewbie01232015
MatlabNewbie01232015 2015년 2월 3일
Thank for helping me out. The problem is the plot becomes a mess because I try to display the output of an audio file segment by segment. Is there anyway I can clear what on the plot but still keep the axes' range?
Geoff Hayes
Geoff Hayes 2015년 2월 4일
Why not just replace the x and y data from the previous segment? Something like
% plot the first segment
h = plot(x,y);
% use the handle from plot, h, to update with the new segment data
set(h,'XData',xNewSeg,'YData',yNewSeg);
where xNewSeg and yNewSeg are the x and y data from the new segment.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by