Hi everyone,
I am trying to plot data in real-time, as acquired from a NI card (a little different to usual, as it is a SensorDAQ, but should work the same – http://www.vernier.com/products/interfaces/sdaq/). I have followed the instructions as per the MATLAB documentation (https://uk.mathworks.com/help/daq/examples/acquire-continuous-and-background-data-using-ni-devices.html), but it won't plot in real-time. It just waits until the end of the script and then plots the figure.
addpath('SensorDAQ')s = sdaq.createSession;sdaq.addSensor(s,1,sdaq.Sensors.HandDynamometer);s.Rate = 100;s.DurationInSeconds = 5;s.NotifyWhenDataAvailableExceeds = 100;lh = addlistener(s,'DataAvailable', @(src,event) plot(event.TimeStamps, event.Data));startBackground(s);s.wait();delete(lh)
I have also tried alternatives, for example using a nested function with drawnow. But it still doesn't plot anything until the script has finished running. See below:
function test_script() addpath('SensorDAQ')s = sdaq.createSession;sdaq.addSensor(s,1,sdaq.Sensors.HandDynamometer);s.Rate = 100;s.DurationInSeconds = 5;s.NotifyWhenDataAvailableExceeds = 100;lh = addlistener(s,'DataAvailable', @plotData);s.startBackground()wait(s)delete(lh) function plotData(src,event) plot(event.TimeStamps,event.Data) drawnow pause(0.1) endend
Any ideas? I've tried running this on Matlab 2014a and 2016b.
Best Answer