Timer - plotting graph to axe in current figure

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

采纳的回答

Adam
Adam 2016-4-7
编辑:Adam 2016-4-7
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 个评论
Adam
Adam 2016-4-7
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by