Extrapolate or interpolate between 2D matrices

27 次查看(过去 30 天)
Hi, I have for ex. a number of 5 2D matrices each 600x600 large. They are placed at z-level 20,30,40,50,60.
I want to interpolate between the z-level matrices at intervals 20:1:60. The output should therefore be 41 matrices of 600x600. The size of the 2D should therefore stay the same.
Can anyone please help me? I have tried interp3 and cat to put the matrices together but interp3 wants to interpolate the 600x600 as well.
In fact, i want to extrapolate to 1:1:80 but that might be too difficult...

采纳的回答

Stephen23
Stephen23 2015-4-8
编辑:Stephen23 2015-4-8
Whatever you do, do not try to create multiple individual output variables: simply perform the calculation and then keep the results in one numeric array. Learn to use the dimensions of arrays instead of using individual variables. Creating variables dynamically is not recommended.
Here is a simple example of how interpolation of an array works. Firstly we define an array where the first dimension represents the z level, and each z level is made up from 2x2 matrices:
>> A(3,:,:) = [1,2;9,8];
>> A(2,:,:) = [3,4;7,6];
>> A(1,:,:) = [5,8;3,2];
which gives an array with three z levels, each of size 2x2. We can then interpolate between these 2x2 matrices very easily using interp1, which interpolates along the first dimension of the input array:
>> B = interp1([20,40,60], A, 20:10:60);
Where the [20,40,60] are the original z values, and 20:10:60 are the output z values. Now, to check the output, lets view the second interpolated set of values, corresponding to z=30:
>> squeeze(B(2,:,:))
ans =
4 6
5 4
You can see that the values are halfway between those defined in A(1,:,:) and A(2,:,:). And we can also look at the range of values for any one point in the matrix, eg (1,1) for all z:
>> B(:,1,1)
ans =
5
4
3
2
1
and (2,2) for all z:
>> B(:,2,2)
ans =
2
4
6
7
8
Note that the function interp1 supports extrapolation, but you will need to set some options for this.
If you want to rearrange the dimensions of the input or output arrays then you can use permute, e.g. to make the third dimension correspond to z:
>> permute(B,[2,3,1])
ans(:,:,1) =
5 8
3 2
ans(:,:,2) =
4 6
5 4
ans(:,:,3) =
3 4
7 6
ans(:,:,4) =
2 3
8 7
ans(:,:,5) =
1 2
9 8

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by