function isok = isvalid(obj)
%ISVALID True for serial port objects that can be connected to device.
%
%    OUT = ISVALID(OBJ) returns a logical array, OUT, that contains a 0 
%    where the elements of OBJ are deleted serial port objects and a 1 
%    where the elements of OBJ are valid serial port objects. 
%
%    An invalid serial port object (an object that has been deleted) 
%    cannot be connected to the device. An invalid serial port object
%    should be cleared from the workspace with CLEAR.
%
%    See also SERIAL/DELETE.
%

%    MP 7-13-99
%    Copyright 1999-2000 The MathWorks, Inc. 
%    $Revision: 1.4 $  $Date: 2000/08/29 23:48:16 $


% Call isvalid on the java object.
try
    jobject = igetfield(obj, 'jobject');
    size_jobject = size(jobject);
    isok = zeros(1, max(size_jobject));
    for i=1:max(size_jobject)
    	isok(i) = isvalid(jobject(i));
    end
catch
   error(lasterr);
end

if ([1 max(size_jobject)] ~= size_jobject)
	isok = isok';
end

isok = logical(isok);
