问题
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?
Please tell me what should I do.
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
This is my test code.
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')
matlab message: Error using griddedInterpolant The grid vectors are not strictly monotonic increasing.
回答1:
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);
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.
来源:https://stackoverflow.com/questions/17649205/how-to-use-interpn-on-non-monotonic-data