function [A,numItems] = createSparseMatrix( m, n, maxItems, minVal, maxVal )
% createSparseMatrix.m
% [A] = createSparseMatrix( m, n, numItems, minVal, maxVal )
% create test input for students to test their programs

if (maxItems > m*n | maxItems < 0)
  error('createSparseMatrix: maxItems has bad value');
end

% Generate random vectors of length maxItems. The entries are
% integers between 1 and m or n
A_sort = zeros(2,maxItems);
A_sort(1,:) = ceil(unifrnd(0,m,1,maxItems));
A_sort(2,:) = ceil(unifrnd(0,n,1,maxItems));

% the columns of this matrix must be unique so that each value gets
% put in a unique field in the sparse matrix
A_sort = unique(A_sort','rows')';
numItems = size(A_sort,2);

% Generate a sparse matrix with numItems entries. The way this
% command works is that it takes coordinates A_sort(1,i), A_sort(2,i), and puts
% field i from the random vector generated by unifrnd at that
% coordinate in the sparse matrix.
A = sparse(A_sort(1,:), A_sort(2,:), ceil(unifrnd(minVal-1,maxVal,1,numItems)),m,n);
