Live Plotting while Acquiring Data without losing the data (NI USB-6009)
6 次查看(过去 30 天)
显示 更早的评论
Hi,
I am not totally sure how to ask the question I have as I am kind of thrown into data acqusition area without any prior knowledge of theory or practice.
I am using Data Acquisition toolbox to collect voltage data using NI USB-6009 using an analog input. I need to store this data in an array AND display it real-time while data is being acquired. I found following documentation:
Using this, I can create a live plot via assigning the function handle to dq.ScansAvailableFcn. However, as the function reads the data, the buffer is emptied, and I can not figure out a way to retain it. Is there a way to use the read function without deleting the acquired data (so I can read all at the end of the background process while showing it)? Or better yet, am I even asking the right question?
0 个评论
采纳的回答
Walter Roberson
2021-8-7
https://www.mathworks.com/help/daq/log-analog-input-data-to-a-file-using-ni-devices.html shows an example of logging to a file.
That particular example shows plotting after everything is done, but the code could easily have been changed to plot as you are going.
The basic idea is to fwrite the data as it comes in, and after everything is done, read it back from the file.
If you happen to have a situation where you can set a strict upper bound on the number of samples to be read in, and all of the samples will fit in memory, then instead of writing to the file, you can pre-allocate space for the maximum possible number of samples and have the callback function assign into that array. Do not use
samples = [samples, newsamples]
or
samples(end+1) = newsample;
because doing that forces a lot of data copying that will slow the system down too much.
If there is a reason why you cannot allocate the full buffer right at the beginning, but you are still sure that you have implemented an upper limit, then at the very least avoid re-allocating too much. For example you could allocate a cell array, and you could put a megabyte's worth of samples into each cell location; that would avoid allocating a lot of memory at one time and yet not have to rewrite memory in any array.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!