function B = matperm(A,perm_vector)
% function MATPERM permutes the rows of matrix A according to the permutation 
%	vector perm_vector.
%
%	B = matperm(A,perm_vector)
%
%	B: the matrix A permuted according to perm_vector
%	A: the orginal matrix to be permuted
%	perm_vector: the vector detailing the permutation (a row vector)
%	NOTE: perm_vector must be a permutation of the integers 1,...,m where
%	m is the number of rows in A.
%

% all we really need to do is reoder the rows of the identity matrix I and  
% then apply that matrix to A to get the desired result.

% reorder the rows of I
I = eye(size(A,1));
J = [];
for i = 1:size(perm_vector,2)

		 J(i,:) = I(perm_vector(i),:);
end

% now J is the correct permutation matrix
B = J*A;
end
