function disparray(M, sorted, minval)
% DISPARRAY Display a multi-dimensional array, with one entry per line preceeded by its index vector.
% disparray(M) displays the entries in standard order.
% disparray(M, 1) displays the entries sorted in decreasing order.
% disparray(M, 1, minval) only displays entries whose value is greater than minval

if nargin < 2, sorted = 0; end
if nargin < 3, minval = -inf; end
  
sz = size(M);

if sorted
  [M, I] = sort(M(:));
  M = reverse(M);
  I = reverse(I);
else
  I = 1:prod(sz);
end
  
for i=1:prod(sz);
  if M(i) > minval
    index = ind2subv(sz, I(i));
    fprintf(1, '%d ', index);
    fprintf(1, ': ');
    fprintf(1, '%6.4f\n', M(i));
  end
end
