如何在非单调数据上使用interpn [英] How to use interpn on non-monotonic data
问题描述
以下是我的数据的一部分.第一列R是我从实验中获得的值,而X Y Z是坐标.我正在尝试使用matlab n-D插值函数. Matlab说我的坐标不是单调增加的值.但是我无法更改或重新排列我的坐标.
Below is some part of my data. The 1st column R is the value I got from the experiment, and X Y Z are the coordinates. I am trying to use matlab n-D interpolation function. Matlab said my coordinates are not monotonic increased value. But I cant change or rearrange my coordinates.
我使用了错误的功能吗?
Did I use the wrong function?
请告诉我该怎么办
R X Y Z
5.05256e-18 0.016 0.015 0.032
4.99958e-18 0.016 0.015 0.064
5.04485e-18 0.016 0.015 0.128
5.49613e-18 0.016 0.0195 0.032
5.45348e-18 0.016 0.0195 0.064
5.43161e-18 0.016 0.0195 0.128
5.9393e-18 0.016 0.03 0.032
5.98785e-18 0.016 0.03 0.064
6.01929e-18 0.016 0.03 0.128
6.54936e-18 0.016 0.06 0.032
6.45947e-18 0.016 0.06 0.064
6.52379e-18 0.016 0.06 0.128
5.06516e-18 0.032 0.015 0.032
5.04897e-18 0.032 0.015 0.064
5.14022e-18 0.032 0.015 0.128
5.45993e-18 0.032 0.0195 0.032
5.4616e-18 0.032 0.0195 0.064
5.38434e-18 0.032 0.0195 0.128
5.94097e-18 0.032 0.03 0.032
5.91148e-18 0.032 0.03 0.064
6.05671e-18 0.032 0.03 0.128
6.56989e-18 0.032 0.06 0.032
6.58173e-18 0.032 0.06 0.064
6.45971e-18 0.032 0.06 0.128
这是我的测试代码.
我想获得X = 0.06 Y = 0.07 Z = 0.08处的插值
I want to get the interpolation value at X=0.06 Y=0.07 Z=0.08
interpn(X,Y,Z,R,0.06,0.07,0.08,'linear')
interpn(X,Y,Z,R,0.06,0.07,0.08,'linear')
matlab消息: 使用griddedInterpolant时出错 网格矢量不是严格单调递增的.
matlab message: Error using griddedInterpolant The grid vectors are not strictly monotonic increasing.
推荐答案
恐怕您的问题超出了向量的单调性.要在这种情况下使用interpn,您还需要将R设为3维矩阵.同样,0.06和0.07的值似乎分别在X和Y的范围之外.
I am afraid that your problem goes a bit beyond the monotony of the vectors. To use interpn in this case you would also need R to be a 3 dimensional matrix. Also the values for 0.06 and 0.07 seem to be outside the range of X and Y respectively.
如果您可以解决范围问题,请尝试使用功能
If you can fix the range problem, try using the function
yi = griddatan(x,y,xi)
在您的情况下,情况看起来像这样:
In your case the thing would look like:
Grid=[X,Y,Z];
Point=[0.03,0.05,0.08] % with values inside the grid and maybe transposed like Point=[0.03;0.05;0.08]; I don't know, didn't try it myself.
Result=griddatan(Grid,R,Point);
希望能奏效,就像我在上面写的那样,我没有尝试运行它,所以您可能必须在这里和那里转置这些东西才能使它起作用,但是我几乎可以肯定griddatan()应该能解决问题
Hope that works, as I wrote above, I didn't try running it, so you might have to transpose the things here and there to get it working, but I'm almost sure that griddatan() should do the trick.
这篇关于如何在非单调数据上使用interpn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!