在Matlab中使用diag函数时出现内存不足错误 [英] out of memory error when using diag function in matlab

查看:350
本文介绍了在Matlab中使用diag函数时出现内存不足错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个值是double M的数组,其中size(M)= 15000

I have an array of valued double M where size(M)=15000

我需要使用diag(M)命令将此数组转换为对角矩阵

I need to convert this array to a diagonal matrix with command diag(M)

但是我遇到了著名的错误out of memory

but i get the famous error out of memory

我运行带有选项-nojvm的matlab以获得内存空间

I run matlab with option -nojvm to gain memory space

并在Windows上使用optin 3GB开关

and with the optin 3GB switch on windows

我也尝试将数组转换为双精度

i tried also to convert my array to double precision

但问题仍然存在

还有其他想法吗?

推荐答案

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

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

这篇关于在Matlab中使用diag函数时出现内存不足错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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