read data from ni-daq in matlab

To read data from NI-DAQ in MATLAB, you can use the daq.createSession function to create a session object and configure the data acquisition channels. Here, you should pass the installed driver name as an input parameter. If you are not sure about the driver name, you can check it in the device manager.

main.m
% create a session and add an analog input channel
s = daq.createSession('ni');
addAnalogInputChannel(s,'Dev1', 0, 'Voltage');

% set the sampling rate and duration of acquisition
s.Rate = 1000;
s.DurationInSeconds = 1;

% start the acquisition
[data, time] = s.startForeground();
281 chars
11 lines

In the above code, we are creating a session object with the NI driver installed on the system, adding an analog input channel, setting the sampling rate and duration of acquisition to acquire a signal for 1 second.

We then start the acquisition using the startForeground function, which returns the acquired data and time.

Note: In the addAnalogInputChannel function, 'Dev1' is the device name/ID and 0 is the channel number. Change the device name and channel number according to your DAQ configuration.

related categories

gistlibby LogSnag