To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016
I am using MATLAB 7.12 with Data Acquisition Toolbox 2.18. I am new to MATLAB, and am trying to simply plot an input voltage versus time in real time. I am able to plot for some duration (say ten seconds), but I have only been able to obtain one of the following results:
1) I have to wait the full ten seconds to see the graph 2) I can see one second of real-time data at a time, and then at the end of the ten seconds the entire graph becomes visible.
I would like to see the entire graph from the beginning, and watch it update as the daq collects more data.
No products are associated with this question.
function acquireData s = daq.createSession('ni'); s.addAnalogInputChannel('cDAQ1Mod1',0,'voltage') s.Rate = 2000 s.DurationInSeconds = 10; lh = s.addlistener('DataAvailable',@plotData); s.startBackground(); % Do something while(~s.IsDone) end
plot(data); % plot global data function plotData(src,event) persistent tempData; persistent tempTimeStamps; if(isempty(tempData)) tempData = ; tempTimeStamps = ; end tempData = [tempData;event.Data]; tempTimeStamps = [tempTimeStamps; event.TimeStamps]; plot(tempTimeStamps,tempData); end
Use a timer function with a timerperiod of give or take 0.25s (depends on how fast your machine is)
Use the peekdata function to pull the most recent samples and plot them all inside the timer function.
obj.SampleRate; obj.Timerperiod; obj.SamplesAvailable;
will also be your friends (in the timerfunction that does the plotting). I'm on a Macintosh without the DAQ toolbox and I haven't used it in about three years; sorry I can't be more specific.