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!