Passing varibales between two callback in GUI

1 回表示 (過去 30 日間)
Ricardo Duarte
Ricardo Duarte 2020 年 9 月 18 日
コメント済み: Ricardo Duarte 2020 年 9 月 21 日
Dear all,
I really need your help.
I'm new using Gui and I'm trying to use one variable in one callback that was calculated previously in other callback.
Let's say:
I have this first callback, named - pushbutton2_selectfile:
function pushbutton2_selectfile_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2_selectfile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
where I have for example the following code:
[xbit,Fs] = audioread(fullfile(path,ifile),'native');
Now, I have another callback (called "pushbutton3_RUN") where I need to use the varibales xbit and Fs
function pushbutton3_RUN_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3_RUN (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I trying to do so by using:
set(handles.pushbutton2_selectfile,'userdata',xbit); %in the first callback
xbit=get(handles.pushbutton2_selectfile,'userdata'); %in the second callback
However i never receive the rigth result.
What am I doing wrong and how can I solve this problem.
Thank you very much for your time and help.

採用された回答

Mohammad Sami
Mohammad Sami 2020 年 9 月 19 日
編集済み: Mohammad Sami 2020 年 9 月 19 日
Use the function setappdata and getappdata instead. An example is shown here in the documentation. https://www.mathworks.com/help/matlab/creating_guis/share-data-among-callbacks.html
You have two options, you can read the section titled Store Data as Application Data Or Store Data Using the guidata Function

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by