% SortCols(a) - sort matrix columns
%
function [b, j] = SortCols(a)

j = [1:size(a,2)];	% column index vector

n = size(a,1);		% rows(a)

for i = 1:n
  [b k] = sort( a(n-i+1,j));	% by row in reverse order
  j = j(k);			% permute index vector
end

b = a(:,j);
