error: refernce to non existent field (handles) GUI

1 view (last 30 days)
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 Comment
Geoff Hayes
Geoff Hayes on 29 Mar 2015
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?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 29 Mar 2015
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);

Categories

Find more on Environment and Settings 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!