GUI operations on matlab objects (non-GUI)

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2011-11-15
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.

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by