function out = vertcat(varargin)
%VERTCAT Vertical concatenation of serial port objects.
%

%    MP 7-13-99
%    Copyright 1999-2000 The MathWorks, Inc. 
%    $Revision: 1.3 $  $Date: 2000/07/19 12:47:37 $

% Initialize variables.
c=[];

% Loop through each java object and concatenate.
for i = 1:nargin
    if ~isempty(varargin{i}),
        % Make sure we are only concatenating instrument objects.
        if ~isa(varargin{i},'instrument'),
            error('Instrument objects can only be concatenated with other instrument objects.')
        end
        
        if isempty(c),
            c=varargin{i};
        else
            % Append the jobject field.
            try
	            c.jobject = [c.jobject; igetfield(varargin{i}, 'jobject')];
            catch
                error(lasterr);
            end
            
            % Append the Type field.
            appendType = igetfield(varargin{i}, 'type');
            if isstr(c.type)
                if isstr(appendType)
                    c.type = {c.type appendType}';
                else
                    c.type = {c.type appendType{:}}';
                end
            else
                if isstr(appendType)
                    c.type = {c.type{:} appendType}';
                else
                    c.type = {c.type{:} appendType{:}}';
                end
            end
            
            % Append the constructor field.
            appendConstructor = igetfield(varargin{i}, 'constructor');
            if isstr(c.constructor)
                if isstr(appendConstructor)
                    c.constructor = {c.constructor appendConstructor}';
                else
                    c.constructor = {c.constructor appendConstructor{:}}';
                end
            else
                if isstr(appendConstructor)
                    c.constructor = {c.constructor{:} appendConstructor}';
                else
                    c.constructor = {c.constructor{:} appendConstructor{:}}';
                end
            end
        end 
    end
end

% Verify that a matrix of objects was not created.
if length(c.jobject) ~= prod(size(c.jobject))
    error('Only a row or column vector of instrument objects can be created.')
end

% Output the array of objects.
out = c;