Live Plotting while Acquiring Data without losing the data (NI USB-6009)
8 views (last 30 days)
Show older comments
Osman Kavcar
on 7 Aug 2021
Edited: Osman Kavcar
on 13 Aug 2021
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 Comments
Accepted Answer
Walter Roberson
on 7 Aug 2021
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.
More Answers (0)
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!