error: refernce to non existent field (handles) GUI

1 次查看(过去 30 天)
hey i am just a beginner so please help my silly question too. i have two radio buttons in my gui and i want to know which one is selected i found a code online but the variable in which i store the value remain local to that 'selectionChange' function
function image_type_SelectionChangeFcn(hObject, eventdata)
handles= guidata(hObject);
switch get(eventdata.NewValue, 'Tag' )
case 'rgbbutton'
handles.im='RGB';
case 'grayscalebutton'
handles.im='grayscale';
end
disp(handles.im);
guidata(hObject,handles);
and hence when i call 'handles.im' in function 'Combine_callback' it gives the error below
reference to non-existent field 'im'
the combine_callback code is as follows
function combine_Callback(hObject, eventdata, handles)
handles=guidata(hObject);
im=handles.im;
disp(im);
please help. this is my project and i need to execute it!
  1 个评论
Geoff Hayes
Geoff Hayes 2015-3-29
Preshma - are you sure that the image_type_SelectionChangeFcn is being called and that the handles.im is being set? I placed your above code in a simple GUI and it did work. When you created the two radio buttons, did you put them in a Button Group panel?

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2015-3-29
Don't call guidata immediately. Try this:
function image_type_SelectionChangeFcn(hObject, eventdata)
radio1 = get(handles.rgbbutton, 'Value');
radio2 = get(handles.grayscalebutton, 'Value');
if radio1
handles.im='RGB';
elseif radio2
handles.im='grayscale';
else
% Should not get this case, but just for robustness...
handles.im = 'Unknown';
end
disp(handles.im);
guidata(hObject,handles);

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by