Can an edit text box's entries be limited to the range of an axis?

1 view (last 30 days)
Within a GUI I have an graph that shows the distribution of different heights at different points on an image. I have a program to plot a line that best fits this graph. There is an edit text box that allows users to estimate the leftmost point on the graph, and I would like to limit entries in this edit text box to the range of values on the graph's x axis. For instance, if the graph's x values go from -5 to -1, I want an error message to appear if a user inserts a value less than -5 or greater than -1. Is there any way to do this? Thank you in advanced for any help.

Accepted Answer

Evan
Evan on 27 Jun 2013
Edited: Evan on 1 Jul 2013
Inside the callback for your edit box, include some statements to check that the data doesn't exceed the bounds. Also, store the value of your editbox in your handles structure so that you can set it to the previous value if the new one entered doesn't meet your criteria
function myedit_Callback(hObject,eventdata,handles)
axlim = get(handles.myaxes,'XLim'); %get axes x limits
xlower = axlim(1);
xupper = axlim(2);
handles.xval = 3; %example previous value. remove for your function.
v = str2double(get(hObject,'String')); %get recently entered string
if > xupper
warndlg(['x should not exceed ' num2str(xupper)])
set(hObject,'String',handles.xval) %set string to previous value
elseif x < xlower
warndlg(['x should not be less than ' num2str(xlower)])
set(hObject,'String',handles.xval) %set string to previous value
else
handles.xval = v; %update saved value
end
guidata(hObject,handles)

More Answers (0)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!