How to make a "moving" graph for a real time signal along the x-axis?
조회 수: 16 (최근 30일)
이전 댓글 표시
Hi All,
I have a piece of code that simulate the plotting of a signal in real time up to 1000 point.
% the data
np=1000;
% prepare the plot
x=1:np;
y=-inf*ones(size(x));
lh=line(x,y);
shg;
% Plot data live
for i=1:np
ix=rem(i-1,np)+1;
y(ix)=.10*fix(i/np)+rand; % <- new data
set(lh,'ydata',y);
pause(.0001);
end
I would like to seek your help on how to make the data "move" along the x-axis. Foe example, after the graph plot from 0 to 50 point. The origin 0 change to start from 51 to 100. Then 100 change to 101. I would like the plot to "Scrolled" towards the left. The purpose of me implementing this function is because the data is getting "cramp up" for displaying all the data from 0 to 1000. I think my description is not very good. I had included a youtube link which is similar to what that I would like to achieve.
https://www.youtube.com/watch?v=d3B4akZiHgo Thank You!
댓글 수: 1
John BG
2017년 3월 16일
you may consider axis shifting x1, dx y1 y2 constant
axis([x1 x1+dx y1 y2])
and apply drawnow after each plot so the graph is updated
채택된 답변
John BG
2017년 3월 16일
편집: John BG
2017년 3월 19일
Hi Jeff
you may consider axis shifting x1, dx y1 y2 constant, with
axis([x1 x1+dx y1 y2])
and apply drawnow
for ..
plot(..);drawnow
end
after each plot in the loop so the graph is updated accordingly.
A simple implementation is:
clear all;clc
x=[0:.01:16]
y=sin(3*x)
figure(1);hold all
Dx=50;y1=-1.2;y2=1.2;
for n=1:1:numel(x)
plot(x,y);axis([x(n) x(n+Dx) y1 y2]);drawnow
end
The link supplied by Jan Simon is a search result in the MATLAB exchange, some of the results are static, there are sliders on plots, I understood that you want it shifting, like the YouTube example you mention in the question, correct?
If you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer
please click on the thumbs-up vote link
thanks in advance
John BG
댓글 수: 2
Caleb Schear
2020년 12월 23일
this works fine, is there any way to make the code halt when I click exit, it just keeps running until the X axis reaches 16
추가 답변 (3개)
Jan
2017년 3월 16일
This is a common problem and as usual several people have posted solutions in the FileExchange:
댓글 수: 0
Risith Ravisara
2017년 9월 27일
hear is the code
T = 500;
passo = 1;
t=1;
x=0;
while 1
b=analogRead(a,0);
x=[x,b];
plot(x);
%pay attention to this command %
axis([T*fix(t/T),T+T*fix(t/T),0,1024]);
grid
t=t+passo;
drawnow;
end
댓글 수: 0
Caleb Schear
2020년 12월 23일
what I did was just put
xlim([(i-10) i])
after the pause function
it worked but if it moves too fast change the pause time or enlarge the i-n value (I used 10 it can be much larger)
댓글 수: 1
Bala Naga Jyothi V
2021년 7월 22일
I am looking to track the realtime moving object to plot the history data.
But nothing is working either drawnow,etc..,
function setax(Position, srf_in)
figure(1)
hold off
srf_in = srf_in + repmat([Position(1) Position(2) Position(3)],[16 1])
h=plot3(srf_in(:,1),srf_in(:,2),srf_in(:,3),'b',"MarkerSize",10);
% h.Color = 'red';
hold on
ax = gca;
ax.FontSize = 12;
ax.TickDir = 'out';
ax.TickLength = [0.02 0.02];
ax.XLim = [-50 50];
ax.YLim = [-50 50];
ax.ZLim = [-50 50];
addpoints(h,Position(1), Position(2),Position(3));
drawnow
% ax.XLim = [-110 110];
% ax.YLim = [-110 110];
% ax.ZLim = [-110 110];
xlabel('X (m)');
ylabel('Y (m)');
zlabel('Z (m)');
grid on
% end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!