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