问题描述
让我们考虑一下我有一组点,它们被描述为一对2D坐标.在每个点上,我都有一个给定参数的值,比方说温度.
Let us consider I have a set of points, which are described as a pair of 2D coordinates. At every single point, I have the value of a given parameter, let us say, temperature.
第2点:(x2, y2, t2)
...
点n:(xn, yn,tn)
所有这些点都包含在一个2D域(形状为三角形)中.
All those points are contained within a 2D domain which is shaped as a triangle.
我想在整个域的扩展范围内内插参数t.对我来说,任何插值方法(线性,最近邻,...)都可以.我深信我可以使用MATLAB来实现这一点-更准确地说,是使用 TriScatteredInterp
.但是,它似乎不起作用.它无法创建插值.
I would like to interpolate parameter t within the extend of the entire domain. Any interpolation method (linear, nearest neighbors,...) would be fine, to me. I am deeply convinced I achieve this using MATLAB - more precisely using TriScatteredInterp
. However, it does not seem to work. It fails to create the interpolant.
这是我到目前为止尝试过的:
Here is what I have tried so far :
x = [0, 1, 1, 0]
y = [0, 0, 1, 1]
t = [10, 20, 30, 20]
F = TriScatteredInterp(x, y, t)
最后一行会产生以下错误:
The last line yields the following error :
输入数据必须以列向量格式指定.
Input data must be specified in column-vector format.
看来我给输入的方式是错误的.尽管找不到问题,但我已经对Google进行了一些研究.
It seems the way I have given the input is wrong. I have made some research over Google, though I couldn't find the problem.
非常感谢您的帮助.
推荐答案
错误非常明显...它说数据必须在列向量中.您将它们作为行向量.简而言之,在调用函数之前先转置数据:
The error is pretty clear... it says the data must be in column vectors. You have them as row vectors. Simply put, transpose your data before calling the function:
>> F = TriScatteredInterp(x.', y.', t.')
F =
TriScatteredInterp with properties:
X: [4x2 double]
V: [4x1 double]
Method: 'linear'
FWIW,如果您阅读了文档,将会看到列向量是必需的: http://www.mathworks.com/help/matlab/ref/triscatteredinterp.html
FWIW, if you read the documentation, you would see that column vectors are required: http://www.mathworks.com/help/matlab/ref/triscatteredinterp.html
创建插值后,可以使用要在插值中使用的任何大小的任何(x,y)
坐标,并且结果将给出与x
和y
的大小匹配的插值.所以这样的事情可能会起作用:
Once you create your interpolant, you can use any (x,y)
coordinates of any size to be used in the interpolant, and the result will give interpolated values that match the size of both x
and y
... so something like this could work:
[X,Y] = meshgrid(linspace(min(x),max(x)), linspace(min(y),max(y)));
out = F(X,Y);
输出将是应用于插值器的(x,y)
坐标的网格...基本上,您将使用X
和Y
作为唯一的(x,y)
对获得插值曲面.
The output will be a grid of (x,y)
coordinates that was applied to the interpolant... basically, you would get an interpolated surface using X
and Y
as unique (x,y)
pairs.
这篇关于使用TriScatteredInterp(Matlab)进行2D插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!