-3

Let's say I have a 3-by-3 matrix of the following values in Matlab:

A = [1 3 5;  3 5 7;  5 7 9];

How can I interpolate my matrix for example to be:

A = [1 2 3 4 5;  2 3 4 5 6;  3 4 5 6 7;  4 5 6 7 8;  5 6 7 8 9];

So in this case all the integer "between values" were added in the matrix. How can I do this in the general case with chosen precision? For example If my matrix is again:

A = [1 3 5;  3 5 7;  5 7 9];

How can I interpolate A to be:

A = [1 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3 3.2 .........4.8 5;  1.2 1.4 1.6 1.8 2.0  .......... 5.2; 1.4 1.6 .... etc. ];

Hope my question is clear =) I want to interpolate the "between values" with chosen precision, both in X and Y direction.

I came across with interp2-function, but I'm not sure how to use it and thought If someone familiar with this problem could tell the answer faster =)

Thank you any help!

4

1 回答 1

3

来自help interp2

ZI = INTERP2(X,Y,Z,XI,YI) 插值以找到 ZI,即矩阵 XI 和 YI 中的点处的基础二维函数 Z 的值。矩阵 X 和 Y 指定给出数据 Z 的点。

XI can be a row vector, in which case it specifies a matrix with
constant columns. Similarly, YI can be a column vector and it 
specifies a matrix with constant rows. 

ZI = INTERP2(Z,XI,YI) assumes X=1:N and Y=1:M where [M,N]=SIZE(Z).
ZI = INTERP2(Z,NTIMES) expands Z by interleaving interpolates between
every element, working recursively for NTIMES.  INTERP2(Z) is the
same as INTERP2(Z,1).

所以,对于你的例子,

 >> A = [1 3 5;  3 5 7;  5 7 9];
 >> A2 = interp2(A, 1)  % call of type INTERP2(Z,NTIMES)

 A2 =
     1     2     3     4     5
     2     3     4     5     6
     3     4     5     6     7
     4     5     6     7     8
     5     6     7     8     9

 >> [X,Y] = meshgrid(1:0.1:3);
 >> A3 = interp(A, X,Y)  % call of type INTERP2(Z,XI,YI)
 >> 

 A3 =
     1.0000    1.2000    1.4000    1.6000    1.8000    2.0000    2.2000 ...
     1.2000    1.4000    1.6000    1.8000    2.0000    2.2000    2.4000 ...
     1.4000    1.6000    1.8000    ...
     ...
于 2013-05-28T13:57:43.330 回答