How to pass a struct between callbacks in GUI?

9 Ansichten (letzte 30 Tage)
Valentino
Valentino am 19 Feb. 2015
Kommentiert: Geoff Hayes am 24 Feb. 2015
Hello, i want to load a file(.mat) which has a struct in it in my GUI. There is one button for picking the file and loading it and one button which should use the values(matrices) stored in the struct for calculations. So i Need to pass the loaded struct from one caallback to another... I'm using guide. Thanks

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 22 Feb. 2015
Valentino - just save the structure to handles in one callback so that the other callback has access to it. For example, if the following is the callback to choose and load the contents of a file
function pushbutton1_Callback(hObject, eventdata, handles)
% choose the file
% load the data into a structure myData
% add the structure to handles
handles.myData = myData;
% save the updated structure
guidata(hObject,handles);
Now in your other callback, you can access this structure directly as
function pushbutton2_Callback(hObject, eventdata, handles)
if isfield(handles,'myData')
% do something with myData
end
Try implementing the above and see what happens!
  1 Kommentar
Geoff Hayes
Geoff Hayes am 24 Feb. 2015
Valentino's answer moved here
Thank you very much Geoff!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by