Specify hardware channel ID
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.
All channels contained by a device object have a hardware channel ID and an associated MATLAB index. The channel ID is given by HwChannel and the MATLAB index is given by the Index property. The HwChannel value is defined when hardware channels are added to a device object with the addchannel function.
The beginning channel ID value depends on the hardware device. For National Instruments® hardware, channel IDs are zero-based (begin at zero). For sound cards, channel IDs are one-based (begin at one).
For scanning hardware, the scan order follows the MATLAB index. Therefore, the hardware channel associated with index 1 is sampled first, the hardware channel associated with index 2 is sampled second, and so on. To change the scan order, you can assign the channel IDs to different indices using HwChannel.
Values are automatically defined when channels are added to the device object with the addchannel function. The default value is one.
Create the analog input object ai for a National Instruments board and add the first three hardware channels to it.
ai = analoginput('nidaq','Dev1'); addchannel(ai,0:2);
Based on the current configuration, the hardware channels are scanned in order from 0 to 2. To swap the scan order of channels 0 and 1, you can assign these channels to the appropriate indices using HwChannel.
ai.Channel(1).HwChannel = 1; ai.Channel(2).HwChannel = 0;