필터 지우기
필터 지우기

Plotting subplot in real time Problem

조회 수: 7 (최근 30일)
Lok Yiu To
Lok Yiu To 2017년 5월 5일
댓글: OMARI TAHAR 2020년 5월 27일
I am interfacing Arduino with MATLAB through serial plot. I have an accelerometer that input three values each time into the serial plot. I am trying to plot the 3 channel data into 3 separate subplot in real time. For some reason, only my last subplot will continuous scroll and the first two will stay at one scroll window.
if(scrollWidth > 0)
set(plotgraph1,'XData',time(time > time(count)-scrollWidth),...
'YData',datax(time > time(count)-scrollWidth));
xlim([time(count)-scrollWidth time(count)]);
set(plotGraph2,'XData',time(time > time(count)-scrollWidth),...
'YData',datay(time > time(count)-scrollWidth));
xlim([time(count)-scrollWidth time(count)]);
set(plotGraph3,'XData',time(time > time(count)-scrollWidth),...
'YData',dataz(time > time(count)-scrollWidth));
xlim([time(count)-scrollWidth time(count)]);
end

채택된 답변

Jan
Jan 2017년 5월 5일
xlim([time(count)-scrollWidth time(count)])
This updates the X-limits of the current axes. If you only set the XData of an existing line object (created by a plot command), the current axes does not change. Therefore define the affected axes explicitely:
xlimit = [time(count)-scrollWidth, time(count)];
set(axes1, 'xlim', xlimit);
and the same for the other two axes also - assuming that axes1 is defined accordingly. You can set all three axes with one command also:
set([axes1, axes2, axes3], 'xlim', xlimit);
  댓글 수: 4
Jan
Jan 2017년 5월 8일
No, this will not work. But you can create two line objects in the same axes:
AxesH = axes('NextPlot', 'add');
plot1graph = plot(AxesH, ?, ?);
plot2graph = plot(AxesH, ?, ?);
And later:
set(plotgraph1,'XData',time(time > time(count)-scrollWidth),...
'YData',datax(time > time(count)-scrollWidth));
set(plotgraph2, 'XData',time(time > time(count)-scrollWidth),...
'YData',datay(time > time(count)-scrollWidth));
OMARI TAHAR
OMARI TAHAR 2020년 5월 27일
Thank you so much!!! :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by