# Custom Matrix Interpolation for every 10 numbers in each column

5 views (last 30 days)
Simone A. on 22 Jan 2023
Commented: Simone A. on 23 Jan 2023
Dear all, I've got a matrix (Mx) 400 x 410. I need to interpolate it to obtain a 2000x2050 matrix. The final result should be almost equal to Fx (attached matrix. Please note, Fx should be 2000x2050 but the file is too big, so I cropped it to 1000x1000). Given the nature of the matrix (latitude file from a satellite scene), a linear/bilinear/cubic/etc. interpolation introduces an error which makes the interpolated file useless. I figured out what works for me, and I reproduced it in a small sample in Excel (file attached), but I don't have the competencies to write a MATLAB script that can do the same. These are the steps that I need, to obtain the desired result:
1) EDIT*: First, a horizontal interpolation for every row. Taking differences between adjacent points and using 1/5th of those difference to compute the 4 interior points. Produces a matrix (400x2050):
2) Arrange the matrix for vertical interpolation (this step I guess is not needed in MATLAB, it is just to visually explain the theory):
3) I need to compute the interpolation in blocks of 10 numbers. That would be, in the example above, A1 to A10, A11 to A20, etc. This should be done by applying the method below:
x = (A6 - A1)/5;
A1 = A1; This has to remain unchanged.
A2 = A1+x;
A3 = A2+x;
A4 = A3+x;
A5 = A4+x;
A6 = A6; This has to remain unchanged.
A7 = A6+x;
A8 = A7+x;
A9 = A8+x;
A10 = A9+x;
At this point, I need to move to the second block of 10 (i.e., A11 to A20):
x' = (A16 - A11)/5;
A11 = A11; This has to remain unchanged.
A12 = A11+x';
A13 = A12+x';
A14 = A13+x';
A15 = A14+x';
A16 = A16; This has to remain unchanged.
A17 = A16+x';
A18 = A17+x';
A19 = A18+x';
A20 = A19+x';
Then, I should move to the third block of 10 (i.e., A21 to A30)... And so on...
I should repeat the same procedure across all the columns. The final result should look like:

Matt J on 23 Jan 2023
Edited: Matt J on 23 Jan 2023
A=reshape(1:40,[],2);
A(10:end,:)=A(10:end,:)*2;
A=A(1:5:end,:); %hypothetical input
M=5; %upsampling factor
A=kron(A,[1;zeros(M-1,1)]);
N=size(A,1);
fcn=@(z) repelem(z,2*M,1);
B=diff(A(1:M:end,:),1,1);
B=B(1:2:end,:)/M;
C=repmat((0:2*M-1)' ,height(B),1);
B=fcn(B);
result=fcn(A(1:2*M:end,:))+B.*C;
table(A,result)
ans = 20×2 table
A result ________ ________ 1 21 1 21 0 0 2 22 0 0 3 23 0 0 4 24 0 0 5 25 6 26 6 26 0 0 7 27 0 0 8 28 0 0 9 29 0 0 10 30 22 62 22 62 0 0 24 64 0 0 26 66 0 0 28 68 0 0 30 70 32 72 32 72
Simone A. on 23 Jan 2023
That's great too! Thanks a lot Matt!

Walter Roberson on 22 Jan 2023
[Mxrows, Mxcols] = size(Mx);
output = interp1(1:Mxrows, interp1(1:Mxcols, Mx.', 1:.1:Mxcols).', 1:.1:Mxrows);
Simone A. on 23 Jan 2023
Edited: Simone A. on 23 Jan 2023
Hi Walter, if my input were [1 21 221] in [A1 A6 A11],respectively, the outputs you suggested are correct.
Just to confirm, the first batch will go from A1 to A10, with A11 being part of the second batch, running from A11 to A20.
EDIT*: I noticed that step 1 (horizontal linear interpolation, for example using interp1), won't produce the result I need. Instead, could step 1 be adjusted to interpolate the values by taking differences between adjacent points and using 1/5th of those difference to compute the 4 interior points?
I amended the original post accordingly.
Thanks a bunch!

### Categories

Find more on Interpolation in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by