GUIDATA save handles only after exiting callback
Mostra commenti meno recenti
Dear All,
I am currently working on a GUI using Matlab GUIDE.
I work with the handles to store some data to be available for all callbacks.
But here comes my problem.
When I introduce additionnal functions into the different callbacks and if those functions try to add specific data to the handles, I have a feeling that the handles is saved only after the callback terminates.
Here is my concrete example:
% Button Callback
function button1_Callback(hObject, eventdata, handles)
% Call specific function
myFunction(handles);
% Use specific data
myOperation = handles.myData + 1;
% Specific function
function myFunction(handles)
% Store data in handles
handles.myData = 1;
% Save handles
guidata(gcbo, handles);
If I proceed this way, I obtain the following error:
Reference to non-existent field 'myData'.
I partially solved the problem by waiting the callback to be closed. And then myData is indeed available for further processing.
My question is therefore the following:
Am I doing the data storage and save right? Is there a way to make myData available already inside the callback (as it is done in my example)?
I hope I was clear in the definition of my problem, in any case I can provide further information upon request.
Thank you very much for your help and have a nice day.
David N.
Risposta accettata
Più risposte (3)
You are doing it alright. The problem is when you store your handles structure. You use gcbo. So it stores only for that callback. Instead store it in hObject or whatever your handles structure is. In your myFunction write guidata(hObject,handles) rather than using gcbo.
1 Commento
nl2605
il 20 Mar 2014
http://www.mathworks.de/de/help/matlab/ref/guidata.html You can refer to this link in case of any confusion.
David Nguyen
il 20 Mar 2014
1 Commento
nl2605
il 20 Mar 2014
Its still giving the same error? That's strange. Its working fine for me.
David Nguyen
il 20 Mar 2014
0 voti
2 Commenti
nl2605
il 20 Mar 2014
Hmmm...I did something that produces the result. But I am not quite sure if that's the right way to do it. Make handles(the structure) as the output argument of your function 'myFunction'. And then when you call this function, call it like this: handles = myFunction(hObject,handles).
David Nguyen
il 20 Mar 2014
Categorie
Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!