简体   繁体   English

在MATLAB中的指定轴上插补

[英]Interpolate over specified axis in MATLAB

I have an n-dimensional matrix, funtointerpolate , and I wish to perform one dimensional interpolation along one of its axes (let's call it axis m ). 我有一个n维矩阵funtointerpolate ,我希望沿其一个轴(即轴m )执行一维插值。 In Python, interpolate functions such as interp1d allow one to specify the axis of interpolation. 在Python中,诸如interp1d插值函数允许指定插值轴。 In MATLAB, I cannot see an obvious way to do this using interp1 or any other built-in interpolate functions. 在MATLAB中,我看不到一种使用interp1或任何其他内置插值函数的明显方法。 Ideally, the function would look something like 理想情况下,该函数应类似于

interpolatedfun = interp1(funtointerpolate,oldpoints,newpoints,axis = m)

An obvious way to get around this is to loop over all the other axes in funtointerpolate , but this is rather cumbersome. 解决此问题的一种明显方法是在funtointerpolatefuntointerpolate所有其他轴,但这很麻烦。 The motivation for interpolation is that the data in funtointerpolate is evaluated along a non-uniform grid along the m axis. 插值的动机是,沿着m轴沿着不均匀的网格评估funtointerpolate中的数据。 I need it to be uniform along m . 我需要沿着m保持一致。 Mathematically, suppose I have some tensorial object 数学上,假设我有一些张量对象

A_{ijk}

which is evaluated along a non-uniform grid along the j index. 沿着j索引沿着不均匀的网格求值。 Then, I wish to find a new A such that the jth index consists of values evaluated on a uniform grid. 然后,我希望找到一个新的A ,使得第j个索引由在统一网格上评估的值组成。 I know the new uniform grid for the jth index, newpoints , and the old grid oldpoints . 我知道第j个索引的新的统一网格, newpoints和旧的网格oldpoints

You can use the interpn function for this purpose: 您可以为此目的使用interpn函数:

newV = interpn(oldAx1, ..., oldAxM, ..., oldAxN, oldV, ...
               oldAx1, ..., newAxM, ..., oldAxN);

where V is your output. 其中V是您的输出。

(Of course the above is pseudo-code, but it should nicely illustrate the way to solve your problem.) (当然,以上是伪代码,但是应该很好地说明了解决问题的方法。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM