how to share data between callback functions in a GUI

2 ビュー (過去 30 日間)
phani
phani 2011 年 5 月 17 日
編集済み: Arturo Moncada-Torres 2015 年 3 月 30 日
hi every one, i am new to GUI. i am reading a .mat file using a push button. i want to save the data in the file to a variable lets say 'y'. the variable 'y' contains a column vector that is from the .mat file . i want to use the variable 'y' in other callback function in the same GUI. i tried in doing that but i am not able to do that.
please help me. many thanks in advance

採用された回答

Arturo Moncada-Torres
Arturo Moncada-Torres 2011 年 5 月 17 日
編集済み: Arturo Moncada-Torres 2015 年 3 月 30 日
When you wish to have variables that have an scope (that means that are "visible") in all functions of the GUI, you should store them in handles. handles is an structure, so you should need something like this:
% Callback 1
% Retrieve GUI data (the handles structure)
handles = guidata(hObject)
% ...
handles.y = 1:10; % Load the data from the .mat file here
% ...
% Update handles structure
guidata(hObject, handles);
% Callback 2
% Retrieve GUI data (the handles structure)
handles = guidata(hObject);
% ...
handles.x = handles.y .* 3; % Do whatever you want with the "y" data here
% ...
% Update handles structure
guidata(hObject, handles);
The handles = guidata(hObject); and guidata(hObject, handles); lines are important because you need them to keep the GUI "updated".
Hope it helps ;-) .
  4 件のコメント
Indika Kulatunga
Indika Kulatunga 2012 年 4 月 4 日
Thank you very much for the Help.
Anthi
Anthi 2013 年 4 月 6 日
Thank you :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by