Using the diff comand with a 3D array to get Partial derivatives
조회 수: 12 (최근 30일)
이전 댓글 표시
Dear all
I have a 3D Matrix with the Size of 167x176x2000 Datapoints. Now i want to compute the Partial derivatives in X and Y direction of this matrix. The derivatives would have to be computed parallel to the XY-plane.
But i am not quite sure how to use the diff command. In the matlab help it is stated: "Y = diff(X,n,dim) is the nth difference calculated along the dimension specified by dim. The dim input is a positive integer scalar."
Lets asume the Matrix has the name 3D_Matrix the new matrix should be named delta_x_Matrix. Would i have to type:
delta_x_Matrix = diff(3D_Matrix,1,1);
Would
delta_x_Matrix = diff(3D_Matrix,1,2);
compute the derivative in Y-Direction?
All the best
And thank you in advance!
댓글 수: 0
답변 (1개)
Star Strider
2016년 1월 11일
I would use the gradient function, not diff, since gradient is specifically designed to do what you want.
댓글 수: 2
Star Strider
2016년 1월 11일
My pleasure.
The gradient function should not reduce the dimensions of the matrix. I checked it with this code snippet to be sure:
M = randi(9, 5, 6, 7);
[GMx, GMy] = gradient(M);
The ‘GMx’ and ‘GMy’ matrices are the same size as ‘M’ here. If you have unequally-spaced data (the gradient function assumes equally-spaced data), then ‘diffxy’ might be more suitable. I’ve not used it, so I can’t comment on it.
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!