function axisHandles = pairsplot_2(X,labels,truevals)
% PAIRSPLOT Generates a (n x n) grid of subplots
% where the subplot in position (i,j) is 
% a scatterplot of the data in columns i and j of X
% The labels parameter is used for labeling the axis.
if ndims(X)~=2
    ME = MException('pairsplot:ndimsInputError','The input array is not 2-dimensional.');
    throw(ME);
end
[nrows,ncols]=size(X);
if length(labels)~=ncols
    ME = MException('pairsplot:ncolsInputError','The number of labels does not match the number of columns of data.');
    throw(ME);
end

for i=1:ncols
    for j=1:ncols
        if i~=j
            axisHandles(i,j) = subplot(ncols,ncols,(i-1)*ncols+j);
            hold on
            scatter(X(:,j),X(:,i));
            scatter(truevals(j),truevals(i));
            xlim([0 max([2*truevals(j);X(:,j)])]);
            ylim([0 max([2*truevals(i);X(:,i)])]);
            xlabel(labels(j));
            ylabel(labels(i));
            %legend('Estimates','True Value')
        else
            axisHandles(i,j) = subplot(ncols,ncols,(i-1)*ncols+j);
            hist(X(:,j))
        end
    end
end
