How to react on a change of variable from workspace?

17 次查看(过去 30 天)
I would like to have an opportunity to react on value change of any workspace variable during any script runnig or commandline working. I would like to avoid using timer object, which can be used as speedy value checker . I would like to have ValueChangeFcn callback, or sort of that.
  2 个评论
Oleg Komarov
Oleg Komarov 2011-2-4
A thought (not an expert here): overloading subsasgn to check for every NEW assignment?
Siddharth Shankar
Could you provide a little more background? How are these variables in the workspace changing? Who modifies the values, and would it be possible for the program/process that modifies these values to also notify you of having made the change?

请先登录,再进行评论。

采纳的回答

Siddharth Shankar
One POSSIBLE solution if you are not considering a timer object (and assuming that you have a relatively recent version of MATLAB, which supports object-oriented programming with MATLAB classes) is to make these variables "Observable" properties of a MATLAB class. You can then listen to changes of these property values. You could put all the variables that you want to listen to as properties of a MATLAB class. More information available here:
EDIT: Use Dynamic properties in conjunction with the SetObservable attribute for those properties and you should be all set. Here's how to Set dynamic property attributes.

更多回答(2 个)

Brett Shoelson
Brett Shoelson 2011-2-4
I like Siddharth's answer. But as an alternative, you could create a timer object (help TIMER) that, in its callback, looks at the value of a workspace variable and compares it to the old value.
Cheers, Brett

roshana
roshana 2011-4-12
I have a problem, and that's the value for the variables i use in the mfile never change. every time i modify the m file, for instance try to get result with a different image again the m file is run with the same old values. note: I also execute "clear" in the command windows to clear the workspace.
  1 个评论
Walter Roberson
Walter Roberson 2011-4-12
That really should be posed as a new question.
The first thing to try is
rehash
If that does not work, you may have saved your files in one of the toolbox directories, which will cause multiple problems. The work-around is to
rehash toolbox

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by