【问题标题】:Out of memory when using interp1. Matlab使用 interp1 时内存不足。 MATLAB
【发布时间】:2017-06-05 22:58:05
【问题描述】:

我有两个 matlab 可以存储的大量元素的数组。当我尝试使用函数 interp1 使用它们进行插值时,问题就来了。出现错误提示“内存不足 - interp1 中的错误(第 122 行) 如果有的话(差异(X)

    time; % Vector, length(time)=91542016
    Results; % Vector with the results for each time step, length(Results)=91542016
    A=1:1:(10^7); %Vector of positions in which I want to interpolate
    E=interp1(time,Results,A,'previous'); %Vector in which I want to store the interpolation

【问题讨论】:

  • 你能告诉我们你正在使用的代码吗?
  • 根据您想要做的插值类型(线性?),您可以使用循环。它会很慢,但内存效率很高
  • 我想要“以前的”类型插值
  • time 和 Results 每个需要 730 MB 的 RAM,A 和 E 每个需要另外 80MB,总共大约 1.6GB + 一些开销。你有超过 2GB 的内存吗?你的记忆中还有其他大向量吗?
  • 你不能一次考虑A的一部分吗?

标签: matlab memory


【解决方案1】:

尝试将您的数组从'double' 转换为'single'。然后你将使用一半的内存。

【讨论】:

  • 如果我这样做,我会得到下一个错误“使用 griddedInterpolant 时出错。网格向量不是严格单调递增的”
【解决方案2】:

这是一个矢量化的版本:

n = numel(time);
%concatenate time and A and find index of sorted elements
[~, idx] = sort([time A]);
%n (variable length) categories created ,
%each element of time form a category
category = cumsum(idx <= n);
%determine which categories elements of A belong to 
idx_Results = category(idx > n);
out = Results(idx_Results);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 1970-01-01
    相关资源
    最近更新 更多