Matlab: gradient of a scalar field

我是研究僧i 提交于 2019-12-25 04:27:23

问题


I have a data in the following format.

x y density
. .   .
. .   .
. .   .

Here, density is the scalar. How to perform gradient on this dataset? I tried the gradient operator in Matlab. However, it returns only a scalar.

Note: Both x and y are uniformly spaced with unit spacing. The boundary points end as floating point numbers, as it is clipped data.


回答1:


You can sort the rows of your data so that the data points can be reshaped into a 2D matrix. You can then compute the gradient of that.

% Sort so that we get the density into column-major ordering
[~, inds] = sortrows(data(:,[1 2]));

% Reshape the density data so it's [numel(Y) x numel(X)]
density = reshape(data(inds,3), numel(unique(data(:,2))), numel(unique(data(:,1))));

% Compute the X and Y gradients
[FX, FY] = gradient(density);


来源:https://stackoverflow.com/questions/39168471/matlab-gradient-of-a-scalar-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!