function p = isbanded(x,lower,upper)
%MATLAB Code Generation Library Function

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

narginchk(3,3);
eml_invariant(isnumeric(x), ...
    'Coder:toolbox:unsupportedClass',mfilename,class(x));
eml_invariant( ...
    isnumeric(lower) && isnumeric(upper) && ...
    isscalar(lower) && isscalar(upper) && ...
    lower >= 0 && upper >= 0 && ...
    floor(lower) == lower && floor(upper) == upper, ...
    'MATLAB:isbanded:nonNegIntScalar');
p = ismatrix(x);
if p && ~isempty(x)
    m = coder.internal.indexInt(size(x,1));
    n = coder.internal.indexInt(size(x,2));
    upperp1 = coder.internal.indexInt(upper) + 1;
    lowerp1 = coder.internal.indexInt(lower) + 1;
    if upperp1 + 1 <= n
        % Check that the upper triangle above the upper band limit is zero.
        for j = upperp1+1:n
            row = eml_min(m,j-upperp1);
            for i = 1:row
                if ~(x(i,j) == 0)
                    p = false;
                    if ~coder.target('HDL')
                        return
                    end
                end
            end
        end
    end
    if lowerp1 + 1 <= m
        % Check that the lower triangle below the lower band limit is zero.
        col = eml_min(n,m-lowerp1);
        for j = 1:col
            for i = j+lowerp1:m
                if ~(x(i,j) == 0)
                    p = false;
                    if ~coder.target('HDL')
                        return
                    end
                end
            end
        end
    end
end

