Why does gradient function calculate wrong dimensions 1 and 2?
显示 更早的评论
Hi there,
I want to calculate multidimensional gradient of a scalar field. After I got to know the difference between meshgrid and ndgrid (general n-dimensional), I noticed that gradient calculates inconsistently when using with ndgrid.
While meshgrid assumes first dimension as y and second dimension as x, ndgrid does it the other way around (x first, y second). The gradient function does it the same way as meshgrid. Obviously, gradient and meshgrid belong together somehow.
But what should I do to calculate gradients consistently with n dimensions?
Example:
[mshx,mshy,mshz] = ndgrid(0:.1:10,0:.1:10,0:.1:10);
[gxx,gyx,gzx] = gradient(mshx);
[gxy,gyy,gzy] = gradient(mshy);
[gxz,gyz,gzz] = gradient(mshz);
Here all gij are zero except gyx, gxy and gzz.
Is there an elegant way to do that kind of calculus to finally get all gij equal zero except for gxx, gyy, gzz?
Thank you for your help.
Best regards
Michael
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!