- DAQ Toolbox : https://in.mathworks.com/help/daq/getting-started-with-data-acquisition-toolbox.html
- Persistent Variables: https://in.mathworks.com/help/matlab/ref/persistent.html
Live data acquisition and store all data acquired
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello, I have implemented a real time acquisition for acquiring 6 signals:
Dev = 'CDAQ2';
daq.getDevices;
s = daq.createSession('ni');
s.Rate = 100;
s.DurationInSeconds = 20;
DevTot = [Dev,'Mod6'];
ch1 = addAnalogInputChannel(s,DevTot,'ai0','Thermocouple');
ch1.ThermocoupleType = 'K';
ch2 = addAnalogInputChannel(s,DevTot,'ai1',"Thermocouple");
ch2.ThermocoupleType = "K";
ch.ch2 = ch2;
ch3 = addAnalogInputChannel(s,DevTot,'ai2',"Thermocouple");
ch3.ThermocoupleType = "K";
ch.ch3 = ch3;
DevTot = [Dev,'Mod7'];
ch4= addAnalogInputChannel(s,DevTot,'ai0',"Voltage");
ch.ch4 = ch4;
DevTot = [Dev,'Mod8'];
ch5=addAnalogInputChannel(s,DevTot,'ai1',"Current");
ch.ch5 = ch5;
DevTot=[Dev,'Mod5'];
ch6= addAnalogInputChannel(s,DevTot,'ai0',"Voltage");
ch.ch6 = ch6;
k=0;
lh = addlistener(s,'DataAvailable', @plotData);
s.NotifyWhenDataAvailableExceeds = 100;
s.startBackground();
function plotData(src,event,k)
plot(event.TimeStamps, event.Data)
legend('Temperature Stack','Ambient Temperature','Air Temperature' , 'Voltage','H2 flow','Current')
H(1+20*k:20+20*k)=event.Data;
k=k+1;
src.UserData=H;
end
I would like to store all the data acquisition (2000X6 samples) in the matrix H and then in d.UserData, but until now I store in this variable only the last 100X6 samples.
Thanks in advance!
댓글 수: 0
답변 (1개)
Ayush
2023년 11월 3일
Hey Nicolo,
I see that you are working on a data acquisition project in MATLAB by using the Data Acquisition Toolbox to connect to a National Instruments device and acquire 6 analog signals. You are also using a callback function to plot the data and store all the data acquisition (2000X6 samples) in the matrix “H” and then in “d.UserData”, but the provided code is storing only the last 100X6 samples in it.
One possible reason for this is, you are overwriting the previous values every time the callback function is executed. To avoid this, you need to use persistent variables or global variables to keep track of the data and the index “k”.
Please refer to the MathWorks documentation link below for more information on Data Acquisition toolbox and persistent variables:
Hope this helps!
Regards,
Ayush Goyal
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Analog Input and Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!