GUI RadioButton Callback Error In Matlab

4 ビュー (過去 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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by