Add hardware channels to analog input or output object
chans = addchannel(obj,hwch)
chans = addchannel(obj,hwch,index)
chans = addchannel(obj,hwch,'names')
chans = addchannel(obj,hwch,index,'names')
Note: You cannot use the legacy interface on 64-bit MATLAB®. See Working with the Session-Based Interface to acquire and generate data on a 64-bit MATLAB.
An analog input or analog output object.
Specifies the numeric IDs of the hardware channels added to the device object. Any MATLAB vector syntax can be used.
The MATLAB indices to associate with the hardware channels. Any MATLAB vector syntax can be used provided the vector elements are monotonically increasing.
A descriptive channel name or cell array of descriptive channel names.
A column vector of channels with the same length as hwch.
chans = addchannel(obj,hwch) adds the hardware channels specified by hwch to the device object obj. The MATLAB indices associated with the added channels are assigned automatically. chans is a column vector of channels.
chans = addchannel(obj,hwch,'names') adds the hardware channels specified by hwch to the device object obj. The MATLAB indices associated with the added channels are assigned automatically. names is a descriptive channel name or cell array of descriptive channel names.
chans = addchannel(obj,hwch,index,'names') adds the hardware channels specified by hwch to the device object obj. index specifies the MATLAB indices to associate with the added channels. names is a descriptive channel name or cell array of descriptive channel names.
Suppose you create the analog input object AI1 for a National Instruments® board, and add the first four hardware channels (channels 0-3) to it.
AI1 = analoginput('nidaq','Dev1'); addchannel(AI1,0:3);
The channels are automatically assigned the indices 1-4. If you want to add the first four hardware channels to AI1 and assign descriptive names to the channels,
Note that you can use the makenames function to create a cell array of channel names. If you add channels 4, 5, and 7 to the existing channel group,
addchannel(AI1,[4 5 7]);
the new channels are automatically assigned the indices 5-7. Suppose instead you add channels 4, 5, and 7 to the channel group and explicitly assign them indices 1-3.
addchannel(AI1,[4 5 7],1:3);
The new channels are assigned the indices 1-3, and the previously defined channels are reindexed as indices 4-7. However, if you assigned channels 4, 5, and 7 to indices 6-8, an error is returned because there is a gap in the indices (index 5 has no associated hardware channel).
Suppose you create the analog input object AI1 for a sound card. Most sound cards have only two channels that can be added to a device object. To configure the sound card to operate in mono mode, you must specify hwch as 1.
AI1 = analoginput('winsound'); addchannel(AI1,1);
The ChannelName property is automatically assigned the value Mono. You can now configure the sound card to operate in stereo mode by adding the second channel.
The ChannelName property is assigned the values Left and Right for the two hardware channels. Alternatively, you can configure the sound card to operate in stereo mode with one call to addchannel.
The numeric values you supply for hwch depend on the hardware you access. For National Instruments and Measurement Computing™ hardware, channels are "zero-based" (begin at zero). For sound cards, channels are "one-based" (begin at one).
Hardware channel IDs are stored in the HwChannel property and the associated MATLAB indices are stored in the Index property.
You can add individual hardware channels to multiple device objects.
For sound cards, you cannot add a hardware channel multiple times to the same device object.
You can configure sound cards in one of two ways: mono mode or stereo mode. For mono mode, hwch must be 1. For stereo mode, the first hwch value specified must be 1.
Note If you are using National Instruments AMUX-64T multiplexer boards, you must use the addmuxchannel function to add channels.
When you use the sound card, and only one channel is added to an analog output object the card is put into mono mode. The same signal is output to both channels.
Every hardware channel contained by a device object has an associated MATLAB index that is used to reference the channel. Index assignments are made either automatically by addchannel or explicitly with the index argument and follow these rules:
If index is not specified and no hardware channels are contained by the device object, then the assigned indices automatically start at one and increase monotonically. If hardware channels have already been added to the device object, then the assigned indices automatically start at the next highest index value and increase monotonically.
If index is specified but the indices are previously assigned, then the requested assignment takes precedence and the previous assignment is reindexed to the next available values. If the lengths of hwch and index are not equal, then an error is returned and no channels are added to the device object.
The resulting indices begin at one and increase monotonically up to the size of the channel group.
If you are using scanning hardware, then the indices define the scan order.
Sound cards cannot be reindexed.
When using National Instruments 1200 Series hardware, you need to modify the above rules in these ways:
Channel IDs are given in reverse order with addchannel. For example, to add eight single-ended channels to the analog input object ai:
The scan order is from the highest ID to the lowest ID (which must be 0).
There cannot be any gaps in the channel group.
When channels are configured in differential mode, the hardware IDs are 0, 2, 4, and 6.
You can assign hardware channels descriptive names, which are stored in the ChannelName property. Choosing a unique descriptive name can be a useful way to identify and reference channels. For a single call to addchannel, you can
Specify one channel name that applies to all channels that are to be added
Specify a different name for each channel to be added
If the number of names specified in a single addchannel call is more than one but not equal to the number of channels to be added, then an error is returned. If a channel is to be referenced by its name, then that name must not contain symbols. If you are naming a large number of channels, then the makenames function might be useful. If a channel is not assigned a descriptive name, then it must be referenced by index.
A sound card configured in mono mode is automatically assigned the name Mono, while a sound card configured in stereo mode is automatically assigned the names Left for the first channel and Right for the second channel. You can change these default channel names when the device object is created, or any time after the channel is added.