Data Acquisition Toolbox
  Function/Property:
    Search    Help Desk 

Reordering Channels

As described in "Adding Channels to an Analog Input Object", when channels are added to a device object with the addchannel function, a mapping is defined between hardware channel IDs and MATLAB indices. This mapping allows you to configure specific hardware channels to suit your data acquisition needs.

If you are using scanning hardware, then this mapping also establishes the channel scanning order. The hardware scan order is given by the elements of the HwChannel property. Namely, the first HwChannel element is sampled first, the second HwChannel element is sampled second, and so on. The scan order can be easily displayed by typing the name of the device object at the MATLAB command line and observing the elements of HwChannel. Under certain circumstances, you may want to explicitly reorder an existing channel group. There are three ways hardware channels can be reordered:

These methods of reordering channels are discussed below.

Note:
Channels cannot be reordered for sound cards. The rules for adding and deleting hardware channels for sound cards are described in "Example: Adding Channels for a Sound Card".

Swapping MATLAB Indices

You can reorder an existing channel group by swapping the MATLAB indices of the channels with the Channel property.

For example, suppose you created the analog input object myAI and added hardware channels 0-2 to it. If the second hardware channel is to be a trigger, but you want that channel to be the first one sampled, then you can swap the indices for channels one and two.

Note that when swapping indices, you must explicitly specify the complete index permutation. You cannot specify just the indices you want to swap.

Adding Channels to an Existing Channel Group

Channel reordering can occur when you add channels to an existing channel group. When adding channels, these rules must be followed:

If channels are added to an existing channel group and channel indices are not provided, then the MATLAB indices are automatically assigned the next available values, in order. For example, suppose hardware channels 3 and 4 are added to myAI using the next available indices.

The channel group now contains hardware channels 0 to 4 which correspond to indices 1 to 5, respectively.

If channels are added to an existing channel group and channel indices are provided but previously assigned, then the previously assigned channels are reindexed to the next available values, in order. For example, suppose hardware channels 3 and 4 are added to myAI and assigned indices 2 and 3.

The channel group now contains hardware channels 0 to 4 which correspond to indices 1, 4, 5, 2, and 3, respectively.

The figure below illustrates this situation.


Deleting Channels From an Existing Channel Group

You can delete channels from a channel group with the delete command. When a channel is deleted, it is removed from the channel group and the indices of the remaining channels are reindexed such that the rules described on page 4-11 are satisfied.

For example, suppose you want to delete hardware channels 1 and 2 from the modified channel group shown above.

The new channel group now contains hardware channels 0, 3, and 4 which correspond to the indices 1,2, and 3.

The figure below illustrates this situation.


As mentioned in "Copying Device Objects", you cannot delete valid channels using the clear command. clear removes the variable from the MATLAB workspace but it does not remove objects from the engine.

Note:
As in Handle Graphics, the clear and delete functions are not equivalent.



[ Previous | Help Desk | Next ]