Data Acquisition Toolbox
  Function/Property:
    Search    Help Desk 

Reference by Channel Name

In some circumstances it may be useful to reference one or more channels by name rather than by index. Names are associated with channels through the ChannelName property. You can assign channel names through the addchannel function or by directly assigning values to ChannelName.

For example, suppose you want TrigChan to be the name of the first channel in myAI's channel group. After naming the channel, you can configure its property values by referencing the channel by its name. This feature is illustrated in the example below.

Initialization: Create the analog input object myAI for a sound card. The installed adaptors and hardware ID's are found with daqhwinfo.

Configuration: Add two hardware channels to myAI, define an eight second acquisition duration, copy channel 1 to the variable chan1, assign a name to channel 1, and set a property value by referencing the channel name. The actual sampling rate is retrieved since it may be set to a value that differs from the specified value.

Execution: Start myAI and wait for the device object to stop running. Eight seconds of data is collected for each channel contained by myAI.

Termination: Display summary information and delete myAI.

Alternatively, you can define a channel name with the addchannel function.

Note:
You cannot reference a channel by name if that name does not have the appropriate format. A channel name must contain only letters, numbers, and underscores and must begin with a letter.

To quickly generate a list of channel names, you can use the makenames function. This function is described below.

The makenames Function

You can generate a list of channel names with the makenames function.

where:

For example, suppose you want to add hardware channels 5-7 to myAI and assign the names Chan6, Chan7, and Chan8 to these new channels. You can create the channel names using makenames and then pass the resulting cell array to addchannel.

Alternatively, you can assign names to channels after they have been added to the object.



[ Previous | Help Desk | Next ]