在Matlab中更快的插值方法 [英] faster method of interpolation in matlab

查看:147
本文介绍了在Matlab中更快的插值方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用interp1整合一些数据:

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

在这里,我通过将测量值从1 m增量插值到0.5 m增量来提高测量分辨率.该代码可以正常工作,即它为我提供了我正在寻找的矩阵.但是,当我将其应用于实际数据时,需要花费很长时间才能运行,主要是因为我正在运行一个遍历各个单元的附加循环.有没有一种方法可以在不使用循环的情况下实现上述目的,换句话说,有没有一种更快的方法?

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?

推荐答案

将for循环替换为:

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

如果更改temp的定义方式,并且i_temp是19x365数组而不是365x19的行,则可以摆脱转置.

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.

顺便说一句,interp1的文档非常清楚,您可以将数组传递为第二个参数.

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

这篇关于在Matlab中更快的插值方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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