错误:超出了程序允许的最大变量大小.在使用sub2ind时 [英] Error:Maximum variable size allowed by the program is exceeded. while using sub2ind

查看:1013
本文介绍了错误:超出了程序允许的最大变量大小.在使用sub2ind时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请建议如何解决此问题:

Please suggest how to sort out this issue:

nNodes = 50400;
adj = sparse(nNodes,nNodes);

adj(sub2ind([nNodes nNodes], ind, ind + 1)) = 1; %ind is a vector of indices
??? Maximum variable size allowed by the program is exceeded.

推荐答案

adj = sparse(ind, ind + 1, ones(size(ind)), nNodes, nNodes, length(ind));

这很好...

而且,如果我们必须访问稀疏矩阵的最后一个元素,则可以通过adj(nNodes,nNodes)进行访问,但是adj(nNodes * nNodes)会引发错误.

And, if we have to access the last element of the sparse matrix, we can access by adj(nNodes, nNodes), but adj(nNodes * nNodes) throws error.

这篇关于错误:超出了程序允许的最大变量大小.在使用sub2ind时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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