Main Content

isvalid

Determine if image acquisition object is associated with image acquisition device

    Description

    tf = isvalid(obj) returns logical 1 (true) if the video input object obj is associated with hardware and logical 0 (false) otherwise. A video input object in the MATLAB® workspace can become invalid when you use the delete command. In this case, use clear to remove the object from the workspace.

    example

    Examples

    collapse all

    Create a video input object, associating it with hardware such as a Windows web cam.

    obj = videoinput("winvideo",1,"MJPG_1280x720");

    If the hardware exists and the object creation was successful, then obj is a valid video input object in the MATLAB workspace.

    tf = isvalid(obj)
    tf =
    
      logical
    
       1
    

    Delete obj.

    delete(obj)

    This command disconnects the camera from the MATLAB session. However, the variable obj still exists in the workspace. obj is now invalid because it is no longer associated with hardware.

    tf = isvalid(obj)
    tf =
    
      logical
    
       0
    

    To remove the object from the workspace, use clear.

    clear obj

    Input Arguments

    collapse all

    Video input object to query, specified as a video input object created using videoinput.

    Output Arguments

    collapse all

    Whether obj is associated with hardware, returned as numeric or logical 1 (true) or 0 (false). If obj is not associated with hardware, use clear to remove it from the MATLAB workspace.

    If obj is an array of video input objects, tf is an array where each element reflects the validity of the corresponding element in obj.

    Version History

    Introduced before R2006a