function p = nzloc(a)
% p = nzloc(a)
%     Returns a list of locations and values at non-zero elements: (i,j,v)
[m n] = size(a);
index = 0;
for ii = 1:m
  for jj = 1:n
    if a(ii,jj) > 0
      index = index+1;
      p(index,1) = ii;
      p(index,2) = jj;
      p(index,3) = a(ii,jj);
    end
  end
end
