function [values,types] = stack(D)
% stack  Convert a multicolumn matrix to a pair of (values,types) vectors
%
% Synopsis: [values,types] = stack(D)
%
% Input: U = matrix where the values in each column are from the D
%             matrix and each column has the same type as indicated
%             by the second column in D
%             
% Output: values = vector of values sorted by the columns of
%            second column is an integer indicating the type
%

% -- Use outer product to create a matrix where columns are uniform integers
[m,n] = size(D);
T = ones(m,1)*(1:n);

% -- Convert the matrix of integers by columns to get the vector of types
%    Convert the matrix of values by columns to get the vector of values
types = T(:);
values = D(:);