Alternative to "drawnow" to plot real time data inside while loop
显示 更早的评论
I'm reading data from ADC in real time (while loop) and I'm trying to plot in real time. Now, I can't use
pause on; hold on; etc
Because it interferes with ADC's API and how it samples the data. My code looks something like that and it does plot in real time.
while true %sampling from ADC
%read data from ADC and update
a = datafromADC;
plot3(t, real(datafromADC), imag(datafromADC))
drawnow;
end
It works but I notice that when I increase sampling rate above certain value, ADC's API crashes, giving me an error pointing to .NET library that stopped working. When I increase sampling rate but comment plot3 and drawnow,
while true %sampling from ADC
%read data from ADC and update
a = datafromADC;
%plot3(t, real(datafromADC), imag(datafromADC))
%drawnow;
end
This code works and I can plot it later but without ability to plot in real time. My theory is that ADC's API and "drawnow" compete for resources and cause API to crash.
Are there alternatives to "drawnow" to plot complex data in real time? Right now my only option is to sample data and store it, terminate "while" loop and run a different script to display it.
3 个评论
Bruno Luong
2019-9-12
"This code works and I can plot it later but without ability to plot in real time. My theory is that ADC's API and "drawnow" compete for resources and cause API to crash. "
My theory is the API is buggy.
Adam Danz
2019-9-12
Paul Pogba's answer moved here as a comment.
I think the problem is that I'm plotting too fast. I'll try to change the code and comment here if it helped.
Bruno Luong
2019-9-12
编辑:Bruno Luong
2019-9-12
You can't plot to fast believe me, using PLOT3 and DRAWNOW.
To plot faster you must use SET(...) + DRAWNOW.
But I bet you can still update your plot faster than 100 Hz, which is slow for a computer.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!