views:

1515

answers:

1

I have a matlab timer object. It is updating a global variable FOO once per second.

I have a matlab GUIDE GUI, with a couple of controls, and a single plot frame. The plot frame gets updated by some of the GUI controls, and it gets updated by the timer object.

Basically, there are two global variable FOO and BAR. The timer updates FOO, the GUI controls updates BAR. updates to either FOO or BAR need to update the GUI.

How to do this?

Thanks John

+3  A: 

You can NOT put a watch on a variable. There is no callback for that. However, both FOO and BAR are being updated by either:


FOO by timerFcn

BAR by widget callbacks


You need to make a function:

updatePlot %updates the plot to reflect new values of FOO or BAR

and have both of the functions that update either FOO or BAR call updatePlot as one of their last duties.

I also would recommend against using of global variables. There are better ways to do this. I am a fan of GETAPPDATA and SETAPPDATA. See this video I made about it.

http://blogs.mathworks.com/videos/2005/10/03/guide-video-part-two/

You could also try nested functions.

MatlabDoug
I can't view viedoes from my current location. More details, or an explicit example would be most helpful.
John
I have attempted to do exactly what you say, but every time my "updatePlot" function gets called, it creates a new Plot object. It's like FOO and BAR are rfunning in different contexts.
John
@John: What are you doing within "updatePlot"? Are you using the SET command to change the values of already existing graphics objects, or are you replotting those objects? For example, you *should not* be calling "plot(...)", but instead be calling "set(hPlot,...)" where "hPlot" is a handle to a plot object returned by the PLOT function.
gnovice
John,The link I provided is to downloadable videos. You should be able to see those in any environment.
MatlabDoug