[英]Out of memory error when using '.*' operation in Matlab
Below is the code I used in my m.file: 下面是我在m.file中使用的代码:
for idx = i_start:i_end
CheckTemp = (timeTick > time_tr(idx)) .* (timeTick <= time_tr(idx));
CheckTemp2 = find(CheckTemp);
IdxS = min(CheckTemp2);
IdxE = max(CheckTemp2);
......
the timeTick
array is a double array about 100MB , and idx
is from about 2000 to 4000 . timeTick
数组是一个大约100MB的双数组, idx
是从大约2000到4000 。 Cause I check the m-file step by step, I find that before the loop, my memroy commit charge is: 817M/5422M . 因为我一步一步检查m文件,我发现在循环之前,我的memroy提交费用是: 817M / 5422M 。 There is a lot of free space, right? 有很多自由空间,对吧?
But my Matlab v6.5 told me that: Error in '.*', out of memory
... which makes me really confused. 但我的Matlab v6.5告诉我: Error in '.*', out of memory
...这让我很困惑。
Plus, I executed the code line by line before. 另外,我之前逐行执行了代码。 And no error occurred. 并没有发生错误。 I really don't know why. 我真的不知道为什么。 I hope there is someone who can help... 我希望有人可以提供帮助......
If you need anymore information, please comment. 如果您需要更多信息,请发表评论。
The MATLAB memory management page has some useful information such as the process memory limit on your system. MATLAB 内存管理页面包含一些有用的信息,例如系统上的进程内存限制。 In general, it is a good idea to run clear all
before running a memory-intensive operation. 通常,在运行内存密集型操作之前运行clear all
是个好主意。 Since, as Daniel pointed out, MATLAB's ability to allocate arrays is based on contiguous available memory, and clear
does not guarantee garbage collection, it may be a good idea to restart MATLAB, espeially on older versions. 因为正如Daniel指出的那样,MATLAB分配数组的能力是基于连续的可用内存,而clear
不能保证垃圾收集,重启MATLAB可能是一个好主意,特别是在旧版本上。
On a side note, I suspect that you will find that CheckTemp = (timeTick > time_tr(idx)) .* (timeTick <= time_tr(idx));
另外,我怀疑你会发现CheckTemp = (timeTick > time_tr(idx)) .* (timeTick <= time_tr(idx));
will always give you an array of logical
zeros. 总会给你一系列logical
零。 .*
Acts like binary &
on arrays of logicals and you are guaranteeing that there will be no overlap by comparing >
in one case and <=
in the other. .*
类似于二进制&
逻辑数组,你保证通过比较一个案例中的>
和另一个案例中的<=
来没有重叠。 Perhaps you meant to use something like time_tr(idx-1)
for one of the indices? 也许你打算在其中一个索引中使用类似time_tr(idx-1)
东西?
If timeTick
and timeTr
are sorted, this can be done: 如果timeTick
和timeTr
已排序,则可以执行以下操作:
timeTick
无需创建与timeTick
相同大小的其他数组 timeTick
and timeTr
通过单个传递两个数组timeTick
和timeTr
The code would go as follows (note you must set time_tr(end+1) = inf
for my code to work). 代码如下(注意你必须设置time_tr(end+1) = inf
才能使我的代码工作)。
%This code requires last entry of time_tr to be inf, eg. time_tr(end+1)=inf;
n_tick = length(timeTick);
n_tr = length(time_tr);
IdxS = NaN(n_tr, 1);
IdxE = NaN(n_tr, 1);
i_tick = 1;
i_tr = 1;
window_start_i_tick = 1;
window_end = time_tr(1);
while(i_tick <= n_tick)
t = timeTick(i_tick);
if(t > window_end)
IdxS(i_tr) = window_start_i_tick;
IdxE(i_tr) = i_tick - 1;
window_start_i_tick = i_tick;
i_tr = i_tr + 1;
while(t > time_tr(i_tr)) %take care of case that we skip past a window/windows
i_tr = i_tr + 1;
end
window_end = time_tr(i_tr);
end
i_tick = i_tick + 1;
end
IdxS(i_tr) = window_start_i_tick;
IdxE(i_tr) = i_tick;
Reading the documentation for memory
you will notice that the continuous available address space is the limit. 阅读memory
文档,您会注意到连续可用的地址空间是限制。 Your Matlab version can not use your full memory, it is limited to a 32 bit addresses space. 您的Matlab版本无法使用您的完整内存,它仅限于32位地址空间。
I recommend to switch to a recent 64 bit version of matlab or to octave which is a open source clone. 我建议切换到最近的64位版本的matlab或octave这是一个开源克隆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.