Matlab:标量场的梯度 [英] Matlab: gradient of a scalar field

查看:431
本文介绍了Matlab:标量场的梯度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的数据.

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

在这里,density是标量.如何在此数据集上执行渐变?我在Matlab中尝试了gradient运算符.但是,它仅返回标量.

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.

注意:xy均以单位间隔均匀地间隔开.边界点以浮点数结尾,因为它是剪切的数据.

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

推荐答案

您可以对数据行进行排序,以便可以将数据点重塑为2D矩阵.然后,您可以计算 that 的梯度.

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);

这篇关于Matlab:标量场的梯度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆