GUI operations on matlab objects (non-GUI)

1 view (last 30 days)
I am having difficulty updating an object that I am using in a GUI callback. I am sure there must be a good way around it that I am missing because of my own lack of knowledge. If anyone can help me get around the problem (without undue hardship ;) ), I would appreciate it.
1)Say that I have an object 'obj' with internal variables 'varx' and 'vary'.
2)Say that, within a method of obj, I update obj.varx.
In order to keep the update beyond the duration of the method call, I need to return the object. [e.g. obj = obj.method(...);]
If I pass obj to a GUI callback and perform this operation, I cannot update obj in the main GUI function, because callbacks do not return output. (ex. set(h.toggle_exp, 'Callback', {@toggle, obj, othervar}); Using guidata() doesn't update particular variables, either.
Is the only way to update objects in the parent GUI function to define them as globals? (I hope not, ... ughh ...)
Any thoughts on how to a) update parent object within methods, and/or b) update particular variables within parent function would be awesome.
Thanks in advance, Sean

Accepted Answer

Walter Roberson
Walter Roberson on 15 Nov 2011
You can assignin('caller') but when you are in a GUI callback, the caller is the the base MATLAB workspace. The main GUI function is not a "parent function" to a callback.
You can use nested functions and thus nested variables. This is probably the best way.

More Answers (1)

Sean de Wolski
Sean de Wolski on 15 Nov 2011
And there's always get/setappdata:
doc setappdata
doc getappdata

Community Treasure Hunt

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

Start Hunting!