使用interp1时内存不足。 MATLAB

时间:2017-01-20 21:09:42

标签: matlab memory

我有两个matlab可以存储的大量元素数组。当我尝试使用函数interp1来使用它们进行插值时,问题出现了。有一个错误说"内存不足 - interp1错误(第122行)     如果有的话(diff(X)< 0)" 我有什么选择?

    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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

这是一个矢量化版本:

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);
相关问题