Using the diff comand with a 3D array to get Partial derivatives
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Star Strider
am 11 Jan. 2016
I would use the gradient function, not diff, since gradient is specifically designed to do what you want.
2 Kommentare
Star Strider
am 11 Jan. 2016
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.
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!