diff()函数的⽤法()
摘⾃matlab
diff Difference and approximate derivative.
diff(X), for a vector X, is [X(2)-X(1) X(3)-X(2) … X(n)-X(n-1)].
diff(X), for a matrix X, is the matrix of row differences,
[X(2:n,:) - X(1:n-1,:)].
diff(X), for an N-D array X, is the difference along the first
non-singleton dimension of X.
diff(X,N) is the N-th order difference along the first non-singleton
dimension (denote it by DIM). If N >= size(X,DIM), diff takes
successive differences along the next non-singleton dimension.
diff函数
diff(X,N,DIM) is the Nth difference function along dimension DIM.
If N >= size(X,DIM), diff returns an empty array.
Examples:
h = .001; x = 0:h:pi;
diff(sin(x.^2))/h is an approximation to 2*cos(x.^2).*x
diff((1:10).^2) is 3:2:19
If X = [3 7 5
0 9 2]
then diff(X,1,1) is [-3 2 -3], diff(X,1,2) is [4 -2
9 -7],
diff(X,2,2) is the 2nd order difference along the dimension 2, and
diff(X,3,2) is the empty matrix.
⽤法(翻译)
diff:求差和求导
diff(X):对于⼀个向量来说,diff(X)就是 [X(2)-X(1) X(3)-X(2) … X(n)-X(n-1)] >>>>此时这个向量的维数是n-1维。对于⼀个矩阵来说,结果是:[X(2:n,:) - X(1:n-1,:)];对于⼀个N*D的矩阵,结果是后⼀⾏减前⼀⾏的差值。
diff(X,N) :相当于N阶⾏差分,也就是相当于做N次diff(x),如果N⼤于x的⾏数,则最终会成为⼀个[]。>>空单个元素的矩阵diff(X,N,DIM) :做N次差分。DIM是⽅向。>>DIM=1表⽰⾏差分;DIM=2表⽰列差分。
总结:
diff(x)= diff(x,1)=diff(x,1,1);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。