GUI operations on matlab objects (non-GUI)

조회 수: 2 (최근 30일)
Sean
Sean 2011년 11월 15일
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에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by