Real time plot from streaming data

조회 수: 37 (최근 30일)
Rui
Rui 2013년 9월 17일
댓글: Zibo Wang 2017년 6월 1일
How can I plot a graph in real time with data being streamed from yahoo.finance?
Should I use an infinite while loop or a timer? I think neither the two are the most correct solutions since one will always be constrained by their latency and one just want to update the graph whenever the variable is updated.

답변 (4개)

Nathan Crosty
Nathan Crosty 2013년 9월 17일
Try this code snippet I have in my inventory as an example.
t = 0 ;
x = 0 ;
startSpot = 0;
interv = 1000 ; % considering 1000 samples
step = 0.1 ; % lowering step has a number of cycles and then acquire more data
while ( t <interv )
b = sin(t)+5;
x = [ x, b ];
plot(x) ;
if ((t/step)-500 < 0)
startSpot = 0;
else
startSpot = (t/step)-500;
end
axis([ startSpot, (t/step+50), 0 , 10 ]);
grid
t = t + step;
drawnow;
pause(0.01)
end
  댓글 수: 1
Zibo Wang
Zibo Wang 2017년 6월 1일
great! I like this, thank you so much

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


Rui
Rui 2013년 9월 20일
Thanks Nathan. But I was trying to update my plot in real time with an alternative method, other than through while loop or timer.
I have actually built the code instead with a timer and works perfectly, but I found that
"Note:   The timer object is subject to the limitations of your hardware, operating system, and software. It is not intended to be used for real-time applications.".
I was trying to figure out which could be the most correct solution to implement in real time scenarios.

Rui
Rui 2013년 9월 20일
Since I am using the timer to update periodically my streaming data, I note that I cannot work on Matlab while the timer is running at the same time.
Is it supposed to happen so?
It's because timer is supposed to work independently and allow one to work freely.

Tim DeWolf
Tim DeWolf 2016년 9월 6일
I'm collecting buffer/queue data from a driver in real time using a MATLAB timer in a GUI (guide) and it works. You can still use MATLAB.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by