I have some values and the location of them on a grid. e.g.

V1=1
V2=2
V3=4
...

I know the location of those values on a fixed spaced grid. e.g.

V2 x x V1 x V3
x  x x x  x x 
V5 x x x V4 V6 

Now what I need is to interpolate the missing values x. e.g. the first row

2 1.66 1.33 1 2.5 4

It's a two dimensional problem. Any hints how I can efficiently solve it? The amount of V may vary. Thanks

有帮助吗?

解决方案

Simple interpolation of irregular grid problem. meshgrid is useful.

x = [4,1,6,5,1,6];
y = [1,1,1,3,3,3];
v = [1,2,4,2,4,5];

[xq,yq] = meshgrid(1:max(x), 1:max(y));
vq = griddata(x,y,v,xq,yq);

You need to explicitly define the x- and y- positions (this case row and column numbers) of your V data. Then use meshgrid to generate a grid (this case the matrix itself). Then use griddata to interpolate the data over the grid that you just created. vq is the resulting matrix you want.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top