Update multiple YData on plot without losing focus

조회 수: 6 (최근 30일)
Allen Kelly
Allen Kelly 2014년 10월 22일
댓글: Allen Kelly 2014년 10월 22일
Hi guys, I'm trying to write some code to periodically update a plot with multiple 'Ydata' sets without losing focus on the current window i'm working on (i.e. Word, Chrome etc...).
At the moment I perform the calculations on the data then update the plot with a for loop in the following manner:
for...
figure(h);
plot(t_whole,'-k');
hold on
plot(fit.mode,'-b');
plot(fit.mean,'-r');
axis tight
drawnow
hold off
end
This works to update the plot but then steals the focus back to the figure each time the plot is updated (approx every 6-12s depending on the data set)
Ideally I would want to use
set(h,'YData',...);
which wouldn't steal focus, but i'm not sure how to do that for the 3 data sets I have (t_whole,fit.mode,fit.mean). Any suggestions?
Thanks, Allen

채택된 답변

Ced
Ced 2014년 10월 22일
where do you get your data from? In general, what I would do is the following, if you want to plot your three sets of data into a single plot:
1. plot the first set of data and save the handles, e.g.
figure(h)
hold on
handle1 = plot(t_whole,'-k');
handle2 = plot(fit.mode,'-b');
handle3 = plot(fit.mean,'-r');
2. Then, you can change your sets (probably through your for loop) and update them individually using the handles, meaning something like
for ...
set(handle1,'YData',t_whole_new)
set(handle2,'YData',fit.mode)
set(handle3,'YData',fit.mean)
drawnow
end
Hope this helps

추가 답변 (1개)

Robert Cumming
Robert Cumming 2014년 10월 22일
you need to save the handles for each of your 3 plots
h1 = plot ( t_whole, '-k');
h2 = plot ( fit.mode,'-b');
h3 = plot ( fit.mean,'-r');
then when you update you do
set(h1.YData,....)
set(h2.YData,....)
set(h3.YData,....)
  댓글 수: 1
Allen Kelly
Allen Kelly 2014년 10월 22일
As above. Looks like you guys answered at pretty much the exact same time :)

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by