function H = hankel(c,r)
%MATLAB Code Generation Library Function

%   Copyright 1984-2017 The MathWorks, Inc.
%#codegen

coder.internal.assert(nargin > 0,'MATLAB:minrhs');
coder.internal.assert(coder.internal.isBuiltInNumeric(c) || ...
    islogical(c),'Coder:toolbox:unsupportedClass',mfilename,class(c));
nrows = coder.internal.indexInt(numel(c));
if nargin == 2
    coder.internal.assert(coder.internal.isBuiltInNumeric(r) || ...
        islogical(r),'Coder:toolbox:unsupportedClass',mfilename,class(r));
    % There is no conflict to warn about if there are no elements.
    if ~isempty(c) && ~isempty(r) && c(nrows) ~= r(1) && ...
            ~coder.setwarningflag
        coder.internal.warning('MATLAB:hankel:AntiDiagonalConflict');
    end
    % Type inference works via VERTCAT in HANKEL.
    czero = coder.internal.scalarEg(c);
    rzero = coder.internal.scalarEg(r);
    hzero = coder.internal.scalarEg([czero;rzero]);
    ncols = coder.internal.indexInt(numel(r));
else
    hzero = coder.internal.scalarEg(c);
    ncols = nrows;
end
H = coder.nullcopy(zeros(nrows,ncols,'like',hzero));
for j = 1:eml_min(nrows,ncols)
    jm1 = j - 1;
    istop = nrows - jm1;
    for i = 1:istop
        H(i,j) = c(i + jm1);
    end
    for i = istop + 1:nrows
        if nargin == 2
            H(i,j) = r(i - istop + 1);
        else
            H(i,j) = hzero;
        end
    end
end
for j = nrows + 1:ncols
    jmnrows = j - nrows;
    for i = 1:nrows
        if nargin == 2
            H(i,j) = r(i + jmnrows);
        else
            H(i,j) = hzero;
        end
    end
end
