Custom Matrix Interpolation for every 10 numbers in each column
조회 수: 2 (최근 30일)
이전 댓글 표시
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):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1271370/image.png)
2) Arrange the matrix for vertical interpolation (this step I guess is not needed in MATLAB, it is just to visually explain the theory):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1271375/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1271380/image.png)
Your help is massively appreciated!
댓글 수: 0
채택된 답변
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)
댓글 수: 5
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
추가 답변 (1개)
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
2023년 1월 23일
If the input were [1 21 221] then could you work through the desired outputs please?
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!