I'm writing a MATLAB GUI code that includes radiobuttons and corresponding edit boxes. To explain my problem better, I created a basic GUI as in the figure. If I first enter a value to the edit box and select the corresponding radiobutton, I obtain the result. However, I want to select the radiobutton first, then I will enter a value to the edit box. I tried several ways including while loops until the condition is met "while ~isa(handles.edit1,'double') end" and waitfor function but I could not solve the problem. I am adding the relevant parts of the code as well.
function radiobutton_OpeningFcn(hObject, eventdata, handles, varargin)handles.output = hObject;set(handles.radiobutton1,'Value',0);set(handles.radiobutton2,'Value',0);guidata(hObject, handles);function varargout = radiobutton_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output;% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)if get(hObject,'Value')==get(hObject,'Max') res=3*handles.edit1; set(handles.res,'String',res); guidata(hObject, handles);end% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)if get(hObject,'Value')==get(hObject,'Max') res=3*handles.edit2; set(handles.res,'String',res); guidata(hObject, handles);endfunction edit1_Callback(hObject, eventdata, handles)handles.edit1=str2double(get(hObject,'String'));guidata(hObject, handles);function edit1_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction edit2_Callback(hObject, eventdata, handles)handles.edit2=str2double(get(hObject,'String'));guidata(hObject, handles);function edit2_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction uibuttongroup1_SelectionChangedFcn(hObject, eventdata, handles)function res_CreateFcn(hObject, eventdata, handles)
Best Answer