How to plot live data with nidaq (MULTI channel)
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Mario Malic
le 14 Août 2023
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
Réponses (0)
Voir également
Catégories
En savoir plus sur Analog Input and Output dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!