preallocating大阵在MATLAB matfile比其他零东西 [英] Preallocating a large array in a MATLAB matfile with something other than zeroes

查看:191
本文介绍了preallocating大阵在MATLAB matfile比其他零东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个数组,它是太大,无法到内存到.MAT二进制文件。这可以通过 matfile 命令,该命令允许在光盘上。

I need to write an array that is too large to fit into memory to a .mat binary file. This can be accomplished with the matfile command, which allows random access to a .mat file on disc.

我试图preallocate阵列中的这个文件,并通过的 MathWorks公司博客

I am trying to preallocate the array in this file, and the approach recommended by a MathWorks blog is

matObj = matfile('myBigData.mat','Writable',true); 
matObj.X(10000,10000) = 0;

这工作,但给我留下了一个大阵零 - 这是有风险的,因为一些我将与填充它真正的价值也可能是零。对于较小的阵列,我通常会做的。

This works, but leaves me with a large array of zeroes - which is risky, as some of the genuine values that I will be populating it with may also be zero. For smaller arrays, I would typically do

smallarray = nan(20,20);

但是,如果我尝试这种方法的大阵,我得到一个内存不足的错误; presumably的楠()功能是生产大阵 NaN的 S IN内存首。

But if I try this approach for the large array I get an "out of memory" error; presumably the nan() function is producing the large array of NaNs in memory first.

如何preallocate大阵比其他零东西?

推荐答案

这方法对我的作品。请注意,您必须指定矩阵索引的范围内( X(1:10000,1:) 10000),否则你刚才设置的单一元素在 10000,10000 NaN的

This method works for me. Note that you have to specify the range for the matrix index (X(1:10000,1:10000)), otherwise you just set the single element at 10000,10000 to NaN.

matObj = matfile('myBigData.mat','Writable',true); 
matObj.X(1:10000,1:10000) = NaN;

这篇关于preallocating大阵在MATLAB matfile比其他零东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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