poster
2019-12-10, 20:48
给定矩阵中矩阵反对角的向量,是否有一种简单的方法来重构矩阵?
例如,给定
x = [1 2 3 4 5 6 7 8 9] 有什么简单的方法可以将其重构为以下内容?
1 2 4 3 5 7 6 8 9 由于已知原始块的尺寸,因此使此过程稍微容易一些。重建原始矩阵的旋转或转置很好,因为旋转和转置很容易撤消。越快越好,此计算必须在许多x s上完成。
谢谢!
回答:
您可以创建相应的汉克尔 (http://www.mathworks.com/help/techdoc/ref/hankel.html)矩阵并将其用于排序(仅在输出为方矩阵时才有效!):
x = [1 2 3 4 5 6 7 8 9]; %# find size of output (works only with square arrays) n=sqrt(length(x)); %# create Hankel matrix hh = hankel(1:n,n:(2*n-1)); %# sort to get order of elements (conveniently, sort doesn't disturb ties) [~,sortIdx]=sort(hh(:)); %# reshape and transpose out = reshape(x(sortIdx),n,n)'; %'# SO formatting out = 1 2 4 3 5 7 6 8 9
更多&回答... (https://stackoverflow.com/questions/4300793)
例如,给定
x = [1 2 3 4 5 6 7 8 9] 有什么简单的方法可以将其重构为以下内容?
1 2 4 3 5 7 6 8 9 由于已知原始块的尺寸,因此使此过程稍微容易一些。重建原始矩阵的旋转或转置很好,因为旋转和转置很容易撤消。越快越好,此计算必须在许多x s上完成。
谢谢!
回答:
您可以创建相应的汉克尔 (http://www.mathworks.com/help/techdoc/ref/hankel.html)矩阵并将其用于排序(仅在输出为方矩阵时才有效!):
x = [1 2 3 4 5 6 7 8 9]; %# find size of output (works only with square arrays) n=sqrt(length(x)); %# create Hankel matrix hh = hankel(1:n,n:(2*n-1)); %# sort to get order of elements (conveniently, sort doesn't disturb ties) [~,sortIdx]=sort(hh(:)); %# reshape and transpose out = reshape(x(sortIdx),n,n)'; %'# SO formatting out = 1 2 4 3 5 7 6 8 9
更多&回答... (https://stackoverflow.com/questions/4300793)