Timer - plotting graph to axe in current figure
1 view (last 30 days)
Show older comments
Hello, i have problem. I am passing parameters to timer Fcn like this:
%gui openingfcn (not the whole code) + nested timer function in it
myfigure = gcf;
guidata(myfigure,handles);
t = timer;
t.Period = 2;
t.ExecutionMode = 'fixedRate';
t.TimerFcn = @mytimer_cb;
t.BusyMode = 'drop';
t.UserData = myfigure;
start(t);
function mytimer_cb(h,~) % here starts timer nested function
hObject = h.UserData;
handles = guidata(hObject);
Then (lower in the timer Fcn) I want to plot graph in current figure like this:
axes(handles.axes_realbezmod);
h = plot( bezmod_x, bezmod_y, 'ob' );
But the results looks like this (the graph is not in figure):
I tried findall(0,'type','figure'), I tried to set a parent, but it didn't work.
Do you have any other ideas?
Thanks
0 Comments
Accepted Answer
Adam
on 7 Apr 2016
Edited: Adam
on 7 Apr 2016
Try the more explicit version which is always better to use:
h = plot( handles.axes_realbezmod, bezmod_x, bezmod_y, 'ob' );
If that doesn't work it should at least fail in some way other than just creating a new figure which may help diagnose the problem.
Looking again at your code though you seem to be calling your time callback with no arguments passed in whereas the function expects what I assume if a figure handle.
I haven't really used timer for anything but I assume you need more like:
t.TimerFcn = @() mytimer_cb( h );
assuming h is the handle you expect within your timer callback.
3 Comments
Adam
on 7 Apr 2016
Use the same technique. All these functions now accept an axes handle as their first argument in one of the function overloads so e.g.
xlabel( hAxes, 'SomeLabel' )
will explicitly apply the label to the given axes.
I used to uses the technique you use above until I kept running into unexpected (for me back then) issues with new axes getting created or things plotting to the wrong figure. This explicit method of telling it which axes to use avoids all that.
More Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!