
This more closely replicates the streaming use case for the streaming class and animatedline. In the next example we add on data in 1 second increments, keeping visible one minute’s worth of data. The main point of the above example is that animatedline isn’t designed to be super fast at plotting, but rather to handle streaming data more efficiently as new data are added compared to other plotting strategies. Interestingly, if I specify the axis limits ahead of plotting, then the plotBig times drop to ~0.20 s (see potential improvements below for more on this). Note, all results are from my macbook running Matlab 2019a. In the above figure I’m plotting a sine wave sampled at 20 kHz for 20 minutes of data, a duration and sampling rate that might be reasonable for my work. For example if we simply use animatedline to plot the following figure, it is the slowest out of four plot options tested. animatedline handles adding data points to memory efficiently, but it is not clear that it actually has anyway of speeding up normal plotting.
#Size of matlab 2019a code
The main reason for implementing this code was to increase speed of plotting. Here’s an example where we need to add data because the initial data allocation was insufficient.įs = 20000 %sampling rate n_samples_init = fs * 5 %Run for 200 seconds, but only initialize 5 xy = animatedline ( 'MaximumNumPoints', n_samples_init ) %Note the default (below) keeps only 1 million data points then throws a warning %xy = animatedline() set ( gca, 'ylim' ,) %2) Adding data for i = 1 : 200 new_data = linspace ( 0, 1 / i, fs ) x = linspace ( i, i + 1, fs ) addpoints ( xy, x, new_data ) set ( gca, 'xlim' ,) drawnow () end The main two benefits are expanded upon below.

A previous article on the benefits of using the library without streaming is available here. The code is a subset of my plotBig library.

I describe the basics of using the streaming code, expand upon its benefits, explain how it works behind the scenes, and discuss limitations and potential improvements. This post discusses the code I wrote to make plotting of streaming data quick. In retrospect I’m not sure that avoiding Labview was the best decision, but I managed to make something that works.

National Instruments Labview programming language is designed for just this task but I’ve previously run into issues in managing large Labview projects. This latest project however involved human subjects and thus my code needed to run off a USB-powered NI-DAQ, not off ADInstrument’s wall powered device. For our animal work data are captured and plotted with a program called Labchart by ADInstruments. Additionally the data had to be saved to disk, and I had a few experimental control requirements as well, but those are stories for another time.

In a recent project I wanted to be able to plot data from a NI-DAQ as it was acquired.
