且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Matlab中使用diag函数时出现内存不足错误

更新时间:2022-05-20 03:46:52

比生成完整对角矩阵(稀疏)要好得多的方法可以做您可能要尝试做的事情.

There are much better ways to do whatever you're probably trying to do than generating the full diagonal matrix (which will be extremely sparse).

将具有2.25亿个元素的矩阵与其他矩阵相乘也将花费很长时间.

Multiplying that matrix, which has 225 million elements, by other matrices will also take a very long time.

我建议您重组算法,以利用以下事实:

I suggest you restructure your algorithm to take advantage of the fact that:

diag(M)(a, b) =
                   M(a)    | a == b
                   0       | a != b

您将节省大量的时间和内存,而付钱给您的人会更快乐.

You'll save a huge amount of time and memory and whoever is paying you will be happier.

这是对角矩阵的样子:

除沿矩阵对角线的那些条目(行索引等于列索引的条目)外的所有条目均为零.将此示例与您提供的值diag(M) = AM(n) = An

Every entry except those along the diagonal of the matrix (the ones where row index equals the column index) is zero. Relating this example to your provided values, diag(M) = A and M(n) = An