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!