[英]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. 解决此问题的一种明显方法是在
funtointerpolate
中funtointerpolate
所有其他轴,但这很麻烦。 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.