error: refernce to non existent field (handles) GUI
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Geoff Hayes
am 29 Mär. 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?
Antworten (1)
Image Analyst
am 29 Mär. 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);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!