Custom Matrix Interpolation for every 10 numbers in each column
Show older comments
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:

Your help is massively appreciated!
Accepted Answer
More Answers (1)
Walter Roberson
on 22 Jan 2023
[Mxrows, Mxcols] = size(Mx);
output = interp1(1:Mxrows, interp1(1:Mxcols, Mx.', 1:.1:Mxcols).', 1:.1:Mxrows);
5 Comments
Walter Roberson
on 22 Jan 2023
output = interp1(1:Mxrows, interp1(1:Mxcols, Mx.', linspace(1,Mxcols,2000)).', linspace(1,Mxrows,2050));
However, this disagrees with the interpolation diagram that you had earlier posted and then removed.
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;
- So x = (original second - original first)/5
- new first = original first point
- new second = new first + x = original first + 1*(original second - original first)/5
- new third = new second + x = original first + 2*(original second - original first)/5
- new fourth = new third + x = original first + 3*(original second - original first)/5
- new fifth = new fourth + x = original first + 4*(original second - original first)/5
- new sixth = original second = original first + 5*(original second - original first)/5
Number of output points = 6. If you were to continue your steps for another cycle, you would add 5 more rows, getting out 11 total. Another cycle, another 5 points... The total number of output points is 1 + 5*number of cycles.... Which is never a number divisible by 5 !!
A7 = A6+x; A8 = A7+x;
You are using the same increment here as you used for the previous batch of 5 !! Are you sure that is what you want ?? This is not what you explained in those diagrams you had posted!
For example if the input were [1 21 221] then your text says you would calculate x = (21-1)/5 = 4, A1=1, A2=A1+x=1+4=5, A3=A2+x=5+4=9, A4=A3+x=9+4=13, A5=A4+13+4=17, A6=21 (copied), A7=A6+x=21+4=25, A8=A7+x=25+4=29, A9=A8+x=29+4=33, A10=A9+x=33+4=37, A11=221 (copied) . Are you sure you want to take the difference between two adjacent points, divide by 5, and then use that to predict the next 10 points?? Rather than taking differences between adjacent points and using 1/5th of those difference to compute the 4 interior points??
Simone A.
on 23 Jan 2023
Walter Roberson
on 23 Jan 2023
If the input were [1 21 221] then could you work through the desired outputs please?
Categories
Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
