如何在MATLAB中计算换位矩阵

3
1个回答

3

不确定这是否算“作弊”,但你可以尝试:

[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

接着,交换矩阵就是 Y。


1
很棒的答案。如果避免使用 eye(m*n),是否可以减少内存占用问题? - jason
使用speye。顺便说一下,通信矩阵是Y'而不是Y。 - kurokirasama

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接