faster method of interpolation in matlab

北战南征 提交于 2019-12-11 01:40:07

问题


I am using interp1 to inteprolate some data:

temp = 4 + (30-4).*rand(365,10);
depth = 1:10;

dz = 0.5; %define new depth interval
bthD = min(depth):dz:max(depth); %new depth vector

for i = 1:length(temp);
    i_temp(i,:) = interp1(depth,temp(i,:),bthD);
end

Here, I am increasing the resolution of my measurements by interpolating the measurements from 1 m increments to 0.5 m increments. This code works fine i.e. it gives me the matrix I was looking for. However, when I apply this to my actual data, it takes a long time to run, primarily as I am running an additional loop which runs through various cells. Is there a way of achieving what is described above without using the loop, in other words, is there a faster method?


回答1:


Replace your for loop with:

i_temp = interp1(depth,temp',bthD)';

You can get rid of the transposes if you change the way that temp is defined, and if you are OK with i_temp being a 19x365 array instead of 365x19.

BTW, the documentation for interp1 is very clear that you can pass in an array as the second argument.



来源:https://stackoverflow.com/questions/13383445/faster-method-of-interpolation-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!