Timer - plotting graph to axe in current figure

조회 수: 11 (최근 30일)
Dave Novotny
Dave Novotny 2016년 4월 7일
댓글: Dave Novotny 2016년 4월 7일
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.
Dave Novotny
Dave Novotny 2016년 4월 7일
Thanks, everything is working properly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by