| Data Acquisition Toolbox™ | ![]() |
Determine whether device objects, channels, or lines are valid
out = isvalid(obj) out = isvalid(obj.Channel(index)) out = isvalid(obj.Line(index))
obj | A device object or array of device objects. |
obj.Channel(index) | One or more channels contained by obj. |
obj.Line(index) | One or more lines contained by obj. |
out | A logical array. |
out = isvalid(obj) returns a logical 1 to out if obj is a valid device object. Otherwise, a logical 0 is returned.
out = isvalid(obj.Channel(index)) returns a logical 1 to out if the channels specified by obj.Channel(index) are valid. Otherwise, a logical 0 is returned.
out = isvalid(obj.Line(index)) returns a logical 1 to out if the lines specified by obj.Line(index) are valid. Otherwise, a logical 0 is returned.
Invalid device objects, channels, and lines are no longer associated with any hardware and should be cleared from the workspace with the clear function.
Typically, you use isvalid directly only when you are creating your own M-files.
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:
isvalid(ai)
ans =
1To verify the channels are valid:
isvalid(ch)'
ans =
1 1 1 1 1 1 1 1If 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 1Typically, you use isvalid directly only when you are creating your own M-files. Suppose you create the function myfunc for use with the Data Acquisition Toolbox™ software. If myfunc is passed the previously defined device object ai as an input argument,
myfunc(ai)
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.');
endYou can examine the Data Acquisition Toolbox software M-files for examples that use isvalid.
clear, delete, ischannel, isdioline
![]() | issending | length | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |