Invalid handle object, Please help!
Show older comments
I am programming a function for a edit text box that allows the user to input a min and max for the axes in a graph:
function edit1_Callback(hObject, eventdata, handles)
%Input X-Min value for axes1
user_entry = str2double(get(hObject, 'String'));
if isnan(user_entry)
errordlg('You must enter a numeric value.')
uicontrol(hObject)
return
end
set(handles.axes1, 'XLim', [user_entry Inf]);
guidata(hObject, handles);
However, I get a error message saying "Invalid handle object." at the set line. I suspect it has to do with the 'handles.axes1', but I'm not sure how to fix it. Can anyone help? Thanks in advance
3 Comments
Melvin
on 6 Jun 2013
Walter Roberson
on 6 Jun 2013
You have not given us reason to expect that handles.axes1 was ever created, let alone that reason to think it should still be valid. We are going to need to see more of the code, including the code for every routine you invoke between start-up and the time you run into that problem in the callback.
Melvin
on 6 Jun 2013
Answers (1)
Walter Roberson
on 6 Jun 2013
0 votes
It appears then that handles.axes1 was initialized, but that the axes was destroyed before you use it.
The probable reason for that is as described at the beginning of http://www.mathworks.co.uk/matlabcentral/answers/78221-problem-with-axes-handle#answer_87936
7 Comments
Melvin
on 6 Jun 2013
Walter Roberson
on 6 Jun 2013
Which MATLAB version are you using?
At the MATLAB command line, give the command
help hold
Does the output include the line
hold(AX,...) applies the command to the Axes object AX.
??
If you give the command at the command line
dbstop if error
and then run, then when the program stops to report the error, at the K> prompt, give the command
dbup
until it shows that you are at your hold() call. At that point, please show the output of
ishandle(handles.axes1)
Melvin
on 6 Jun 2013
Walter Roberson
on 6 Jun 2013
I believe hold() accepted axes handles back then as well. But ishandle() showing 0 is a problem.
If you put a breakpoint in at the set(), run up to there and then test
ishandle(handles.axes1)
and also show the numeric value of handles.axes1
I suspect that we are going to need to see more code, of every routine involved in the set-up and every routine you invoke up until the edit1 callback is called.
Melvin
on 6 Jun 2013
Walter Roberson
on 6 Jun 2013
Note that
handles.axes1 = axes('XScale', 'linear');
creates a new axis, rather than changing the current handles.axes1 to be linear.
Melvin
on 7 Jun 2013
Categories
Find more on App Building 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!