GUI RadioButton Callback Error In Matlab

조회 수: 3 (최근 30일)
Tyann Hardyn
Tyann Hardyn 2021년 10월 5일
댓글: Tyann Hardyn 2021년 10월 5일
Hi, everyone
Iam just confused, why this can be happened.
I have 4 Button in GUI, the two of them determined by pushbutton callback A, and the two other determined by pushbutton Callback B.
Here is my code for pushbutton Callback A and the two radio Button :
% --- Executes on button press in originlemi.
function originlemi_Callback(hObject, eventdata, handles)
% hObject handle to originlemi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of originlemi
off = [handles.interlemi];
matikan_radio_button(off);
handles.inter = 1;
guidata(hObject, handles);
% --- Executes on button press in interlemi.
function interlemi_Callback(hObject, eventdata, handles)
% hObject handle to interlemi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of interlemi
off = [handles.originlemi];
matikan_radio_button(off);
handles.inter = 2;
guidata(hObject, handles);
function pushbutton3_Callback(hObject, ~, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
....Uigetfile
if file == 1
..... Stuff
if get(handles.originlemi, 'Value')
Stuff
else
if get(handles.interlemi, 'Value')
stuff
end
end
end
The above code is work, But the other code below (code for pushbutton Callback B and the two other radio Buttons) which has the same pattern as above is doesnt work.....
function convertraw_Callback(hObject, eventdata, handles)
% hObject handle to convertraw (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of convertraw
off = [handles.oriraw];
matikan_radio_button(off);
handles.rawmean = 2;
guidata(hObject, handles);
% --- Executes on button press in oriraw.
function oriraw_Callback(hObject, eventdata, handles)
% hObject handle to oriraw (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of oriraw
off = [handles.convertraw];
matikan_radio_button(off);
handles.rawmean = 1;
guidata(hObject, handles);
function pushbutton12_Callback(~, ~, ~)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
....Uigetfile
if file == 1
if get(handles.convertraw, 'Value')
....stuff
else
if get(handles.oriraw, 'Value')
...Stuff
end
end
end
Iam so confused, how it can be happened. All of my code above lies in the same programmagnetku.m and also programmagnetku.fig. If i select one of the two radio button (interlemi or originlemi) and with a single pushbutton of pushbutton3_Callback) , the program will be executed. BUT, when i choose between handles.convertraw or handles.convertraw RadioButton and with pushbutton12_Callback to select data and execute it, the error is shown as below :
Unable to resolve the name handles.convertraw.
Error in programmagnetku>pushbutton12_Callback (line 3547)
if get(handles.convertraw, 'Value')
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in programmagnetku (line 24)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)programmagnetku('pushbutton12_Callback',hObject,eventdata,guidata(hObject))
3547 if get(handles.convertraw, 'Value')
How it can be happened?
Would anyone lend me a hand to solve my problem here? is not logic, why i can get a mistake like this because iam doing the same pattern like another successful code before.... Thank you for anyone. Please help me. /.\ /.\ /.\

채택된 답변

Voss
Voss 2021년 10월 5일
Change this:
function pushbutton12_Callback(~, ~, ~)
to this:
function pushbutton12_Callback(hObject, eventdata, handles)
Then the callback will have access to the handles structure.
  댓글 수: 2
Tyann Hardyn
Tyann Hardyn 2021년 10월 5일
OMG, You were right, iam just concern to do that many of stuff inside the pushbutton function, and didnt noticed that in the very first of callback function. Thank You very much, SIr !!
Tyann Hardyn
Tyann Hardyn 2021년 10월 5일
Its work now... Huff..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by