Custom Matrix Interpolation for every 10 numbers in each column

조회 수: 2 (최근 30일)
Simone A.
Simone A. 2023년 1월 22일
댓글: Simone A. 2023년 1월 23일
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!

채택된 답변

Matt J
Matt J 2023년 1월 23일
편집: Matt J 2023년 1월 23일
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
  댓글 수: 5
Matt J
Matt J 2023년 1월 23일
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
Name Size Bytes Class Attributes A 2000x2050 32800000 double
Simone A.
Simone A. 2023년 1월 23일
That's great too! Thanks a lot Matt!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2023년 1월 22일
[Mxrows, Mxcols] = size(Mx);
output = interp1(1:Mxrows, interp1(1:Mxcols, Mx.', 1:.1:Mxcols).', 1:.1:Mxrows);
  댓글 수: 5
Walter Roberson
Walter Roberson 2023년 1월 23일
If the input were [1 21 221] then could you work through the desired outputs please?
Simone A.
Simone A. 2023년 1월 23일
편집: Simone A. 2023년 1월 23일
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!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by