| Data Acquisition Toolbox | Search  Help Desk |
| addchannel | Examples See Also |
Add hardware channels to an analog input or analog output object.
Syntax
chans = addchannel(obj, hwch);
chans = addchannel(obj, hwch, index);
chans = addchannel(obj, hwch, names);
chans = addchannel(obj, hwch, index, names);
Arguments
Description
addchannel adds hardware channels to an existing analog input or analog output object. The added channels constitute a channel group. The values you supply for hwch depend on the hardware accessed. For National Instruments hardware, channels are "zero-based" (begin at zero). For Hewlett-Packard hardware and sound cards, channels are "one-based" (begin at one). If in doubt, consult your hardware manual.
A hardware channel can be assigned to multiple device objects, or multiple times to the same device object. For sound cards however, hardware channels cannot be assigned multiple times to the same device object. Furthermore, sound cards can be configured in one of only two ways: mono mode or stereo mode. For mono mode, hwch must be 1, while for stereo mode, hwch must be specified as [1 2].
For every hardware channel contained by a device object, there is an associated MATLAB index that is used to reference the channel. The index assignments follow these rules:
index is not specified, and no hardware channels are assigned to the object, then the assigned indices start at one and increase monotonically. If hardware channels have already been assigned to the object, then the assigned indices start at the next highest index value and increase monotonically.
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.
addchannel call is more than one but less than 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 begin with a character and contain only characters, numbers, and underscores. If you are naming a large number of channels, then the makenames function may be useful. If a channel is not assigned a descriptive name, then it must be referenced by index.
Examples
Sound Card
Suppose you create the analog input objectAI1 for a sound card. Sound cards have 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
and theAI1 = analoginput('winsound')addchannel(AI1, 1);
ChannelName property is assigned the name Mono. You can now configure the sound card to operate in stereo mode by adding the second channel
addchannel(AI1, 2);
ChannelName property is assigned the names 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.
AI1 = analoginput('winsound');
addchannel(AI1, 1:2);
National Instruments
Suppose you created the analog input objectAI1 for a National Instruments board, and add the first four physical hardware channels (channels 0-3).
These channels are automatically assigned the indices 1-4. You can associate descriptive names with channels by passing a cell array of names.AI1 = analoginput('nidaq', 1)addchannel(AI1, 0:3);
addchannel(AI1, 0:3, {'chan1', 'chan2', 'chan3', 'chan4'});
makenames function.
You can add channels 4, 5, and 7 to the existing channel group.
addchannel(AI1, [4 5 7]);
addchannel(AI1, [4 5 7], 1:3);
See Also
Functions
delete, makenames