矩阵运算符将矩阵的行堆叠在“对角线”上

发布于 2025-01-26 06:26:01 字数 465 浏览 2 评论 0原文

我正在寻找一个执行以下操作的矩阵运算符(或数学表达式):

我有一个尺寸3 x 5的矩阵a:

a_11 a_12 a_13 a_14 a_15
a_21 a_22 a_23 a_24 a_25
a_31 a_32 a_33 a_34 a_35

我想获得矩阵3 x 15:

a_11 a_12 a_13 a_14 a_15 0    0    0    0    0    0    0    0    0    0
0    0    0    0    0    a_21 a_22 a_23 a_24 a_25 0    0    0    0    0
0    0    0    0    0    0    0    0    0    0    a_31 a_32 a_33 a_34 a_35

我试图使用kronecker产品,但我没有' T到达任何解决方案。

I am looking for a matrix operator (or a mathematical expression) that does the following:

I have a matrix A of dimension 3 by 5:

a_11 a_12 a_13 a_14 a_15
a_21 a_22 a_23 a_24 a_25
a_31 a_32 a_33 a_34 a_35

I want to obtain the matrix 3 by 15:

a_11 a_12 a_13 a_14 a_15 0    0    0    0    0    0    0    0    0    0
0    0    0    0    0    a_21 a_22 a_23 a_24 a_25 0    0    0    0    0
0    0    0    0    0    0    0    0    0    0    a_31 a_32 a_33 a_34 a_35

I have tried to use Kronecker products but I didn't arrive to any solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵性 2025-02-02 06:26:01

您可以使用以下内容来解决它:

a = [1,2,3;4,5,6;7,8,9]
sz = size(a) % find the dimensions
m = zeros(sz(1), prod(sz)) %Create a matrix of zeros
for row = 1:sz(1)
    m(row,(1:sz(2)) + (row-1) * sz(2)) = a(row,:) %replace each row accordingly
end

m =

     1     2     3     0     0     0     0     0     0
     0     0     0     4     5     6     0     0     0
     0     0     0     0     0     0     7     8     9

You could solve it using the following:

a = [1,2,3;4,5,6;7,8,9]
sz = size(a) % find the dimensions
m = zeros(sz(1), prod(sz)) %Create a matrix of zeros
for row = 1:sz(1)
    m(row,(1:sz(2)) + (row-1) * sz(2)) = a(row,:) %replace each row accordingly
end

m =

     1     2     3     0     0     0     0     0     0
     0     0     0     4     5     6     0     0     0
     0     0     0     0     0     0     7     8     9
吾家有女初长成 2025-02-02 06:26:01

不是矩阵-algebra的表达式,但如果它有所帮助:可以使用 num2cell 将矩阵拆分为其行的单元格数组,然后通过a comma-separated list blkdiag

A = randi(9,3,5); % example input
A_cell = num2cell(A, 2);
result = blkdiag(A_cell{:});

Not a matrix-algebra expression, but in case it helps: this can be easily done using num2cell to split the matrix into a cell array of its rows, and passing a comma-separated list of those rows to blkdiag:

A = randi(9,3,5); % example input
A_cell = num2cell(A, 2);
result = blkdiag(A_cell{:});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文