Hardware Channels or Lines

Add Channels and Lines

Channels and lines are the basic hardware device elements with which you acquire or output data.

After you create a device object, you must add channels or lines to it. Channels are added to analog input and analog output objects, while lines are added to digital I/O objects. The channels added to a device object constitute a channel group, while the lines added to a device object constitute a line group.

The functions associated with adding channels or lines to a device object are listed below.

Table 4-1. Functions Associated with Adding Channels or Lines




Add hardware channels to an analog input or analog output object.


Add hardware lines to a digital I/O object.


Add channels when using a National Instruments® AMUX-64T multiplexer. This applies only to Traditional NI-DAQ boards.

    Note:   The Traditional NI-DAQ adaptor will be deprecated in a future version of the toolbox. If you create a Data Acquisition Toolbox™ object for Traditional NI-DAQ adaptor in R2008b, you will receive a warning stating that this adaptor will be removed in a future release. See the supported hardware page at for more information.

For example, to add two channels to an analog input object associated with a sound card, you must supply the appropriate hardware channel identifiers (IDs) to addchannel.

ai = analoginput('winsound');

    Note   You cannot acquire or output data with a device object that does not contain channels or lines. Similarly, you cannot acquire or output data with channels or lines that are not contained by a device object.

You can think of a device object as a channel or line container that reflects the common functionality of a particular device. The common functionality of a device applies to all channels or lines that it contains. For example, the sampling rate of an analog input object applies to all channels contained by that object. In contrast, the channels and lines contained by the device object reflect the functionality of a particular channel or line. For example, you can configure the input range (gain and polarity) on a per-channel basis.

The relationship between an analog input object and the channels it contains is shown below.

For digital I/O objects, the diagram would look the same except that lines would be substituted for channels.

Hardware Channel IDs to the MATLAB Indices

When you add channels to a device object, the resulting channel group consists of a mapping between hardware channel IDs and the MATLAB® indices.

Hardware channel IDs are numeric values defined by the hardware vendor that uniquely identify a channel. For National Instruments and Measurement Computing™ hardware, the channel IDs are "zero-based" (begin at zero). For sound cards, the channel IDs are "one-based" (begin at one). However, when you reference channels, you use the MATLAB indices and not the hardware IDs. Given this, you should keep in mind that the MATLAB software is one-based. You can return the vendor's hardware IDs with the daqhwinfo function.

For example, suppose you create the analog input object ai for a National Instruments board and you want to add the first three differential channels.

ai = analoginput('nidaq','Dev1');

To return the hardware IDs, supply the device object to daqhwinfo, and examine the DifferentialIDs field.

out = daqhwinfo(ai)
ans =
     0     1     2     3     4     5     6     7

The first three differential channels have IDs 0, 1, and 2, respectively.


The index assigned to a hardware channel depends on the order in which you add it to the device object. In the above example, the channels are automatically assigned the MATLAB indices 1, 2, and 3, respectively. You can change the hardware channels associated with the MATLAB indices using the HwChannel property. For example, to swap the order of the second and third hardware channels,

ai.Channel(2).HwChannel = 2;
ai.Channel(3).HwChannel = 1;

The original and modified index assignments are shown below.

    Note   If you are using scanning hardware, then the MATLAB indices define the scan order; index 1 is sampled first, index 2 is sampled second, and so on.

For digital I/O objects, the diagram would look the same except that lines would be substituted for channels.

Was this topic helpful?