MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   在Matlab中从对角线重建矩阵 (https://www.labfans.com/bbs/showthread.php?t=24166)

poster 2019-12-10 20:48

在Matlab中从对角线重建矩阵
 
给定矩阵中矩阵反对角的向量,是否有一种简单的方法来重构矩阵?

例如,给定

x = [1 2 3 4 5 6 7 8 9] 有什么简单的方法可以将其重构为以下内容?

1 2 4 3 5 7 6 8 9 由于已知原始块的尺寸,因此使此过程稍微容易一些。重建原始矩阵的旋转或转置很好,因为旋转和转置很容易撤消。越快越好,此计算必须在许多x s上完成。

谢谢!



[B]回答:[/B]

您可以创建相应的[URL="http://www.mathworks.com/help/techdoc/ref/hankel.html"]汉克尔[/URL]矩阵并将其用于排序(仅在输出为方矩阵时才有效!):

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

[url=https://stackoverflow.com/questions/4300793]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:03

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.