块矩阵构建Matlab [英] Block matrix building matlab

查看:111
本文介绍了块矩阵构建Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我拥有nxn个矩阵,那么构建此矩阵的最有效方法是什么.

What would be the most efficient way to build this matrix given that I have each of the nxn matrices.

我当时正在考虑创建一个单元格数组,并使用嵌套的for循环对其进行迭代,但是对于大k来说,效率非常低.

I was thinking of creating a cell array and iterating through that using a nested for loop but for large k this would be very inefficient..

推荐答案

示例如何在任意数量的输入矩阵中使用blkdiag:

Example how to use blkdiag with arbitrary number of input matrices:

m = {[1,2; 3, 4]; [10, 11, 12; 13, 14, 15; 16, 17, 18]};  %cell array of matrices
A = blkdiag(m{:})

然后可以通过将矩阵复制到大矩阵中进行修饰A

You can then touch it up by copying matrices into the big matrix A

for(i=1:k-1)
    row_begin = 1 + (i-1)*n;
    row_end   = row_begin + n - 1;
    col_begin = 1 + i*n;
    col_end   = col_begin + n - 1;
    A(row_begin:row_end, col_begin:col_end) = B
end

等...

如果矩阵非常大但非常稀疏,并且算法保留稀疏性,则可以考虑构造

If your matrix is extremely large but extremely sparse and your algorithm preserves sparsity, you may consider constructing a sparse matrix.

这篇关于块矩阵构建Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆