function S = ridgemat(m,n)

% RIDGEMAT   A "ridge" matrix. Used with cross-tabulation tables.
%
%  Example:  ridgemat(3,6)   produces the following 3x6 matrix:
%    0 -1 -2 -3 -4 -5
%    1  0 -1 -2 -3 -4
%    2  1  0 -1 -2 -3
%
%  The input arguments specify the matrix size (see ONES, ZEROS).
%  RIDGEMAT(N) is an N-by-N ridge matrix.
%  RIDGEMAT(M,N) or RIDGEMAT([M,N]) is an M-by-N matrix.
%
%  See also XTAB2, SHIFTMAT.

% Original coding by Alex Petrov, Ohio State University
% $Revision: 1.0 $  $Date: 2000/09/29 16:40 $
%
% Part of the utils toolbox version 1.1 for MATLAB version 5 and up.
% http://alexpetrov.com/softw/utils/
% Copyright (c) Alexander Petrov 1999-2006, http://alexpetrov.com
% Please read the LICENSE and NO WARRANTY statement in ../utils_license.m

%-- Decipher input arguments
if (nargin==1)
  if (length(m)==1)
    n = m ;              % ridgemat(N) --> ridgemat(N,N)
  elseif (length(m)==2)
    n = m(2) ;           % ridgemat([M,N]) --> ridgemat(M,N)
    m = m(1) ;
  else
    error('The first argument must be one- or two-element vector.') ;
  end
elseif (nargin~=2)
  error('At least one input argument expected.') ;
end

%-- Construct the ridge matrix
%   0 -1 -2 -3     1 1 1 1     1 2 3 4
%   1  0 -1 -2  =  2 2 2 2  -  1 2 3 4
%   2  1  0 -1     3 3 3 3     1 2 3 4

V = repmat([1:m]',1,n) ;
H = repmat([1:n] ,m,1) ;
S = V - H ;

%%%%% End of RIDGEMAT.M
