How to plot live data with nidaq (MULTI channel)
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello. I am a student majoring in biomedical engineering.
I want to get live data from multiple sensors using NIDAQ and plot it in MATLAB.
I am currently using the code provided in the link below.
(https://kr.mathworks.com/matlabcentral/fileexchange/124835-data-live-acquisition-live-multi-channel)
I want only one signal to be displayed in one window.
If I get data from 8 sensors, I want 1 signal in each of the 8 windows.
However, in this code, multiple signals are displayed in a single window.
What part of the code (the code in the link above that I am using) can I modify to fix this?
Thanks so much for reading this long post, and thanks in advance to anyone who can help.
Have a great day to everyone who read this!
(If the above code causes any copyright issues, I will remove it immediately, please contact me if you have any problems).
댓글 수: 1
Mario Malic
2023년 8월 14일
Hey, I would suggest you to not use app in that case, it's better if you write your own code for setting up the data acquisition. It is not hard to set it up.
Use the ScansAvailableFcn property of DAQ object to plot the data.
app.DAQObject = daq(vendorID);
app.DAQObject.ScansAvailableFcn = @(src, event) PlotDataAvailable (app, src, event); % Function that plots the collected data
Function is below, data contains all collected data from sensors where each channel is in each column, so you can use it to plot each figure on its own, or plot into each subplot. Good luck
function PlotDataAvailable(app, src, event)
[data, timestamps, ~] = read(src, src.ScansAvailableFcnCount, "OutputFormat", "Matrix");
persistent hPlot;
if all(isempty(hPlot)) || all(~isvalid(hPlot)) % first time plotting
hPlot = plot(app.UIAxes, timestamps, data);
hold(app.UIAxes, "on");
legend(app.UIAxes, hPlot, append({app.DAQObject.Channels.Name}, ' ', {app.DAQObject.Channels.MeasurementType}), ...
'Interpreter', 'none');
else
% Assemble the data
numChannels = size(data, 2);
for i = 1 : numChannels
xData(i, :) = [hPlot(i).XData, timestamps']; % Optimize
yData(i, :) = [hPlot(i).YData, data(:, i)']; % Optimize
end
set(hPlot, {'Xdata'}, num2cell(xData, 2), {'YData'}, num2cell(yData, 2)); % why does this work?!
end
end
답변 (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!