フィルターのクリア

How to plot real-time with nidaq, but see the entire graph as it is plotting?

6 ビュー (過去 30 日間)
Megan
Megan 2011 年 7 月 15 日
コメント済み: W Joey 2015 年 7 月 16 日
Hello,
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.
Any suggestions?
Thanks!
Megan
  1 件のコメント
Chirag Gupta
Chirag Gupta 2011 年 7 月 15 日
Could you post some sample code?
Are you using the new session based interface?

サインインしてコメントする。

回答 (4 件)

Chirag Gupta
Chirag Gupta 2011 年 7 月 15 日
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
  3 件のコメント
Chirag Gupta
Chirag Gupta 2011 年 7 月 15 日
if you are using the older analoginput object interface, then you should refer to this demo "Continuous Acquisition Using Analog Input" that does exactly what you need!
W Joey
W Joey 2015 年 7 月 16 日
I think it works with session-based architecture. But what if i want to get the real-time plot data?

サインインしてコメントする。


Sean de Wolski
Sean de Wolski 2011 年 7 月 15 日
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.
  2 件のコメント
Chirag Gupta
Chirag Gupta 2011 年 7 月 15 日
peekdata
Sean de Wolski
Sean de Wolski 2011 年 7 月 15 日
Ahh of course. Your answer is far better anyway! I'm just dusting the cobwebs off my summer job for 2008.

サインインしてコメントする。


Megan
Megan 2011 年 7 月 18 日
Thanks guys! Hugely helpful :)

Lee Stanley
Lee Stanley 2013 年 5 月 23 日
Hi,
Is there a way to log the plotted data as well?
Thanks.
Stan
  2 件のコメント
Sean de Wolski
Sean de Wolski 2013 年 5 月 23 日
Add a save command in the callback :)
Lee Stanley
Lee Stanley 2013 年 5 月 23 日
編集済み: Lee Stanley 2013 年 5 月 23 日
Hi Sean,
Could you show your coding here from the example stated above? :) By the way, is it possible to acquire and plot all the channels in a plot as well at the same time?
Thanks.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by