interpn returns 对角线而不是插值矩阵

interpn returns diagonal instead of interpolated matrix

在八度音程中使用 interpn 我得到了意想不到的结果:

Data=rand(10,3);
interpn(Data,[1,2,3],1:size(Data,2));

我希望数据的前三行是 returns 包含 [Data(1,1),Data(2,2,),Data(3,3)] 的单行向量。我在文档中遗漏了对这种行为的任何解释,或者这是一个错误?

Function File: VI = interpn (X1, X2, ..., V, Y1, Y2, ...)
Function File: VI = interpn (V, Y1, Y2, ...)

 Perform N-dimensional interpolation, where N is at least two.  Each
 element of the N-dimensional array V represents a value at a
 location given by the parameters X1, X2, ..., XN.  The parameters
 X1, X2, ..., XN are either N-dimensional arrays of the same size as
 the array V in the "ndgrid" format or vectors.  The parameters Y1,
 etc.  respect a similar format to X1, etc., and they represent the
 points at which the array VI is interpolated.

 If X1, ..., XN are omitted, they are assumed to be 'x1 = 1 : size
 (V, 1)', etc.  If M is specified, then the interpolation adds a
 point half way between each of the interpolation points.  This
 process is performed M times.  If only V is specified, then M is
 assumed to be '1'.

没有。第一个参数是您的数据 (V),由于您没有指定 X1 和 X2,因此假定它们是 1:M 和 1:N。然后,您请求使用第二个和第三个参数 Y1 和 Y2 进行插值。

要完成你想要的,你需要做:

[y1, y2] = meshgrid ([1 2 3], 1:columns (Data));
interpn (Data, y1, y2)

或者避免中间变量(更容易真正的nd支持):

interpn (Data, nthargout (1:2, @meshgrid, [1 2 3], 1:columns (Data)){:})