Documentation Center

  • Trial Software
  • Product Updates

isvalid

Determine whether device objects, channels, or lines are valid

Syntax

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 Session-Based Interface to acquire and generate data.

Arguments

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.

Description

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.

Examples

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 =
     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 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,

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.');
end

You can examine Data Acquisition Toolbox software files for examples that use isvalid.

More About

expand all

Tips

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 files.

See Also

| | |

Was this topic helpful?