Determine whether device objects, channels, or lines are valid
out = isvalid(obj)
out = isvalid(obj,Channel(index))
out = isvalid(obj,Line(index))
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.
A device object or array of device objects.
One or more channels contained by obj.
One or more lines contained by obj.
A logical array.
Create the analog input object ai for a National Instruments® board and add eight channels to it.
ai = analoginput('nidaq','Dev1'); ch = addchannel(ai,0:7);
To verify the device object is valid:
ans = 1
To verify the channels are valid:
ans = 1 1 1 1 1 1 1 1
If you delete a channel, then isvalid returns a logical 0 in the appropriate location:
ans = 1 1 0 1 1 1 1 1
Typically, you use isvalid directly only when you are creating your own files. Suppose you create the function myfunc for use with Data Acquisition Toolbox™ software. If myfunc is passed the previously defined device object ai as an input argument,
the first thing you should do in the function is check if ai is a valid device object.
function myfunc(obj) % Determine if an invalid handle was passed. if ~isvalid(obj) error('Invalid data acquisition object passed.'); end
You can examine Data Acquisition Toolbox software files for examples that use isvalid.