function isneq=ne(arg1, arg2)
%NE Overload of ~= for serial port objects.
%

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

% Store the warning state.
s = warning;

% Warn appropriately if one of the input arguments is empty.
if isempty(arg1)
	if ~strcmp(s, 'off')
		warning on;
		warning('Future versions will return empty for empty ~= scalar comparisons.');
		warning(s);
	end
	isneq = logical(1);
	return;
elseif isempty(arg2)
	if ~strcmp(s, 'off')
		warning on;
		warning('X ~= [] is technically incorrect. Use isempty(X) instead.');
		warning(s);
	end
	isneq = logical(1);
	return;
end

% Determine if both objects are instrument objects.
if isa(arg1, 'instrument') & isa(arg2, 'instrument')
	
	% Error if both the objects have a length greater than 1 and have
	% different sizes.
	if prod(size(arg1))~=1 & prod(size(arg2))~=1
		if size(arg1,1)~=size(arg2,1) | size(arg1,2)~=size(arg2,2)
			error('Matrix dimensions must agree.')
		end
	end
	
	% If the objects are not of length 1, loop through each object and 
	% determine if they are equal.
	if prod(size(arg1))~=1 & prod(size(arg2))~=1
		
		% Initialize variables.      
		isneq = zeros(size(arg1));
		jarg1 = igetfield(arg1, 'jobject');
		jarg2 = igetfield(arg2, 'jobject');
		
		for i = 1:length(arg1)
			isneq(i) = ~(equals(java(jarg1(i)), java(jarg2(i))));
		end
	elseif prod(size(arg1))==1,
		% If arg1 is of length one, then determine if each element of arg2
		% is equal to arg1.
		
		% Initialize variables.
		isneq = zeros(size(arg2));
		jarg1 = java(igetfield(arg1, 'jobject'));
		jarg2 = igetfield(arg2, 'jobject');
		
		% Loop through each element of arg2 and compare to arg1.
		for i = 1:length(arg2)
			isneq(i) = ~(equals(jarg1, java(jarg2(i))));
		end
	elseif prod(size(arg2))==1
		% If arg2 is of length one, then determine if each element of arg1
		% is equal to arg2.
		
		% Initialize variables.
		isneq = zeros(size(arg1));
		jarg1 = igetfield(arg1, 'jobject');
		jarg2 = java(igetfield(arg2, 'jobject'));
		
		% Loop through each element of arg2 and compare to arg1.
		for i = 1:length(arg1)
			isneq(i) = ~(equals(java(jarg1(i)), jarg2));
		end
	end	
else
	% One of the object's is not an instrument object and therefore unequal.
	% Error if both the objects have a length greater than 1 and have
	% different sizes.
	if prod(size(arg1))~=1 & prod(size(arg2))~=1
		if size(arg1,1)~=size(arg2,1) | size(arg1,2)~=size(arg2,2)
			error('Matrix dimensions must agree.')
		end
	end
	% Return a logical one. 
	isneq = 1;
end

isneq = logical(isneq);