Invalid handle object, Please help!

7 次查看(过去 30 天)
Melvin
Melvin 2013-6-6
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 个评论
Walter Roberson
Walter Roberson 2013-6-6
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
Melvin 2013-6-6
When I perform 'which handles -all; disp(handles);' before the set line, I get the following:
handles is a variable.
figure1: 257.0094
uipanel1: 302.0093
uipanel2: 265.0094
uitoolbar1: 258.0094
edit12: 338.0093
edit11: 337.0093
edit10: 336.0093
edit9: 335.0093
edit8: 334.0093
edit7: 333.0093
edit6: 332.0093
edit5: 331.0093
edit4: 330.0093
edit3: 329.0093
edit2: 328.0093
edit1: 327.0093
text9: 326.0093
text8: 325.0093
text7: 324.0093
text3: 323.0093
text2: 322.0093
text1: 321.0093
popupmenu1: 320.0093
popupmenu3: 319.0093
popupmenu2: 318.0093
axes2: 313.0093
axes1: 308.0093
axes3: 303.0093
edit24: 301.0093
edit23: 300.0093
edit22: 299.0093
edit21: 298.0093
edit20: 297.0093
edit19: 296.0093
edit18: 295.0093
edit17: 294.0093
edit16: 293.0093
edit15: 292.0093
edit13: 291.0093
edit14: 290.0093
text10: 289.0093
text11: 288.0093
text12: 287.0093
text4: 286.0093
text5: 285.0093
text6: 284.0093
popupmenu5: 283.0093
popupmenu4: 282.0093
popupmenu6: 281.0093
axes5: 276.0093
axes4: 271.0093
axes6: 266.0094
uitoggletool5: 264.0094
uitoggletool3: 263.0094
uitoggletool4: 262.0094
uitoggletool2: 261.0094
uitoggletool1: 260.0094
uipushtool2: 259.0094
output: 257.0094
So does this mean that the axes1 is being deleted?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2013-6-6
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 个评论
Walter Roberson
Walter Roberson 2013-6-6
Note that
handles.axes1 = axes('XScale', 'linear');
creates a new axis, rather than changing the current handles.axes1 to be linear.
Melvin
Melvin 2013-6-7
Thanks for your help Walter.
I realized my problem this morning. The subplot function in the open file function was overwriting all of the axes handles I created in the GUI guide. So I removed them and instead placed my data in each by selecting each respective axes with the axes() function and then immediately plotting them.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by