How to set ylim in axes in GUI ?

조회 수: 28 (최근 30일)
Jay Patel
Jay Patel 2019년 7월 23일
댓글: Adam Danz 2020년 8월 8일
My program works around the user input provided from user. It generates graph accordingly.But somehow I had set or default value for axes in Matlab GUI is [999 999] in my case, but my y-axis can be more than that. When i enter the value more than 999 in the text box, GUI didn't execute the function written for pushbutton. This works fine below 1000. I am wondering how can i change the Ylim to auto ?
When you enter 1000 in the 2nd input(Please refer figure), it gives following error:
Error using matlab.graphics.axis.Axes/set
Value must be a 1x2 vector of numeric type in which the second element is larger than the first and may be Inf
Error in axis>LocSetLimits (line 276)
set(ax,...
Error in axis (line 105)
LocSetLimits(ax(j),cur_arg,names);
Error in plotray (line 134)
axis( [ rmin, rmax, zmin, zmax ] )
Error in UnderwaterRayToolbox>pushbutton1_Callback (line 194)
plotray( 'munkp' ), box on, hold on
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in UnderwaterRayToolbox (line 49)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)UnderwaterRayToolbox('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
276 set(ax,...
Can someone suggest how to change the Axes Ylimit to Auto or set to user input ??

채택된 답변

Jay Patel
Jay Patel 2019년 7월 23일
The problem has been solved. main *.m file has to have the ylim function before plotting which controls the plotting. and then either you can copy the axes from figure or call the figure in GUI, both worked.
12.JPG
Thanks everyone, specially Adam and Rik.
Jay
  댓글 수: 3
Jay Patel
Jay Patel 2019년 7월 23일
편집: Jay Patel 2019년 7월 23일
Hi adam,
plotray is also a function which is called by bellhop to plot the output. And what i mean to say by "copy the axes from the figure" is just MAKE AXES CURRENT FIRST and "call the figure in GUI" means copying the current figure(plotted by plotray function)'s all objects in GUI's axes children. This is more specific to my case here. I'm very sorry for not being so much descriptive. In general your answer would make more sense.
Thanks.
Adam Danz
Adam Danz 2019년 7월 23일
If you can, open up plotray() and create an input that allows you to specify the axis handle. If you can do that, no need to use axes() to make an axis current and no need to create a figure and then copy its content into your GUI's axes.

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

추가 답변 (1개)

Adam Danz
Adam Danz 2019년 7월 23일
편집: Adam Danz 2019년 7월 23일
ylim(h,[a,b])
% h: the axis handle
% [a,b] the limits (a<b)
Make sure you're specifying the axis handle (h). Otherwise, the callback function might change the y axis limit of another axes.
  댓글 수: 9
lamine moahmed
lamine moahmed 2020년 8월 8일
Hi jay patel can you halp me
i wont to set xlim and ylim of axes when i plot data of workspace
but when i plot the xlim and ylim change
thank you
Adam Danz
Adam Danz 2020년 8월 8일
Plot the data first, then set the axis limits.
Alternativey, set the axis limits first, then "hold on", then plot the data.

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by