Recently I’ve been working a lot with the Matlab GUI GUIDE.
When I build a GUI, each time I write a callback function, I have to add at the end of the function this line: guidata(hObject, handles); for example:
function someFunction_Callback(hObject, eventdata, handles)
.... %implementation
........
guidata(hObject, handles); <------------
Now I want to understand why I’m adding this line each time I have a function that is related to the GUI.
What really happens behind the scenes? What information does this struct hold?
using guidata is one way to read/store back the user data between callbacks. I typically do this
Unless You read your data earlier using
myData=guidata(object_handle)Then there is no point of doingguidata(object_handle,myData)again,
guidatais just an API for you to use to read/write your data back to the figure internals to be stored there between callbacks. If you do not modify your own data in a callback, there no need to use it. I’d put all my data in astructbecuaseguidataworks for one variable only.So, if you do not modify anything in your data or handles as you show in your example, then no need to use it.