问题
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