Matlab组合数组

时间:2012-07-10 02:59:44

标签: matlab

我在看一些Matlab代码(没有软件)。我想知道以下是什么:

d=[0 diff(fM)]

其中fM本身就是一个数组。

1 个答案:

答案 0 :(得分:0)

Octave中diff的帮助文档(我支持Matlab等效工作与任何其他Matlab / octave函数相同)

help diff
 `diff' is a function from the file /usr/share/octave/3.2.4/m/general/diff.m

 Function File:  diff (X, K, DIM)
 If X is a vector of length N, `diff (X)' is the vector of first
 differences  X(2) - X(1), ..., X(n) - X(n-1).

 If X is a matrix, `diff (X)' is the matrix of column differences
 along the first non-singleton dimension.

 The second argument is optional.  If supplied, `diff (X, K)',
 where K is a non-negative integer, returns the K-th differences.
 It is possible that K is larger than then first non-singleton
 dimension of the matrix.  In this case, `diff' continues to take
 the differences along the next non-singleton dimension.

 The dimension along which to take the difference can be explicitly
 stated with the optional variable DIM.  In this case the K-th
 order differences are calculated along this dimension.  In the
 case where K exceeds `size (X, DIM)' then an empty matrix is
 returned.

基本上,diff返回带有n - 1条目的向量,发布的代码创建一个新数组,在开头添加零,这样新的diff矢量保持与输入向量相同的大小(也许结果向量将用于另一个假定计算输入向量长度的例程,没有其余代码就很难了,希望有帮助