Commutation matrix is defined in: https://en.wikipedia.org/wiki/Commutation_matrix
assume I have matrix
A = [1,2,3;4,5,6];
How to get the Commutation matrix in MATLAB ?
Not sure if it is "cheating", but you can try:
[m, n] = size(A);
I = reshape(1:m*n, [m, n]); % initialize a matrix of indices of size(A)
I = I'; % Transpose it
I = I(:); % vectorize the required indices
Y = eye(m*n); % Initialize an identity matrix
Y = Y(I,:); % Re-arrange the rows of the identity matrix
And the commutation matrix is then Y.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.