Custom Matrix Interpolation for every 10 numbers in each column
3 views (last 30 days)
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!
0 Comments
Accepted Answer
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)
5 Comments
Matt J
on 23 Jan 2023
For the final step, you can just use interp1
A=rand(2000,410);
M=5;
n=size(A,2);
A=interp1(0:n-1,A',0:1/M:n-1/M,'linear','extrap')';
whos A
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 23 Jan 2023
If the input were [1 21 221] then could you work through the desired outputs please?
See Also
Categories
Find more on Interpolation 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!