How to find a matlab code/command that will produce the permutation matrices of a matrix?

Let's consider the example below: I'm given the matrices A and B.

A=[1 2 3;4 5 6; 7 8 9] is a given matrix and B=[9 7 8;3 1 2; 6 4 5] is a permuted version of A.

My goal is to use Matlab to find the Matrices L (that pre-multiply A) and R(that post-multiply A) such that LAR=B.

`A=[1 2 3;4 5 6; 7 8 9]L=[0 0 1;1 0 0;0 1 0] %L is an n by n (3 by 3) that re-order the rows a matrix when it pre-multiply that matrix`

R=[0 1 0;0 0 1;1 0 0] %R is an n by n that re-order the columns of a matrix

B=L*A*R

What's the code or command to find L and R when I know A and B?

## Best Answer