| Data Acquisition Toolbox | Search  Help Desk |
| isvalid | Examples See Also |
Check for valid device objects, channels, or lines.
Syntax
isvalid(obj)
isvalid(obj.Channel(index))
isvalid(obj.Line(index))
Description
isvalid(obj) returns a "1" if obj is a valid device object and a "0" if obj is not a valid device object. An invalid object exists in the workspace but does not exist in the engine. Therefore, invalid objects are no longer associated with any hardware and should be cleared from the workspace.
isvalid(obj.Channel(index)) returns a logical array containing a "1" where the channels associated with obj are valid, and a "0" where they are not. Invalid channels are no longer associated with any hardware and should be cleared from the workspace.
isvalid(obj.Line(index)) returns a logical array containing a "1" where the lines associated with obj are valid, and a "0" where they are not. Invalid lines are no longer associated with any hardware and should be cleared from the workspace.
Note:
isvalid directly only when you are creating your own M-files.
Examples
Suppose you create the analog input objectai for a National Instruments board and add 8 channels to it.
ai = analoginput('nidaq', 1);
ch = addchannel(ai, 0:7);
To verify the device object is valid
isvalid(ai)
ans =
1
To verify the channels are valid
isvalid(ch)
ans =
1 1 1 1 1 1 1 1
If you delete a channel, then isvalid returns a logical "0" in the appropriate location
delete(ai.Channel(3))
isvalid(ch)
ans =
1 1 0 1 1 1 1 1
Typically, you will use isvalid directly only when you are creating your own M-files. Suppose you create the function func for use with the Data Acquisition Toolbox. If func is passed the previously defined device object ai as an input argument
func(ai);the first thing you should do in the function is check if
ai is a valid device object.
You can examine the Data Acquisition Toolbox M-files for examples usingfunction func(obj)% Determine if an invalid handle was passed.if ~isvalid(obj)error('Invalid Data Acquisition object passed.');end
isvalid.
See Also
Functions
delete, ischannel, isline