Interpolating a 3D Matrix using interp1

조회 수: 2 (최근 30일)
Thomas Holmes
Thomas Holmes 2019년 3월 21일
댓글: Thomas Holmes 2019년 3월 26일
I have a 14x14x221 matrix, A. Using a loop over the third dimension, I'm trying to interpolate the 14x14 matrix at each iteration of this loop to produce a new matrix that has more data points. Then save the new matrix at each iteration to form a new 3D matrix that has X,Y dimensions much greater than 14.
My question is how to use interp1 to spline the 14x14 matrix using the third dimension of the 14x14x221 matrix.

채택된 답변

KSSV
KSSV 2019년 3월 22일
A = rand(14,14,221) ;
% interpolation along row
N = 100 ;
[m,n,p] = size(A) ;
iwant = zeros(m,N,p) ;
xi = linspace(1,n,N) ;
for i = 1:m
for j = 1:p
T = interp1(1:n,A(i,:,j),xi) ;
iwant(i,:,j) = T ;
end
end
A = iwant ;
Repeat the same along columns.
  댓글 수: 1
Thomas Holmes
Thomas Holmes 2019년 3월 26일
I keep getting this error when trying to spline column wise.
"Unable to perform assignment because the size of the left side is 14-by-1 and the size of the right side is 1-by-221" for this line
NewestA(:,g,h) = R;
N = 221 ;
[m,n,p] = size(A) ;
NewA = zeros(m,N,p) ;
xi = linspace(1,n,N) ;
for i = 1:m % Splining row wise
for j = 1:p
T = interp1(1:n,A(i,:,j),xi) ;
NewA(i,:,j) = T ;
end
end
A = NewA ;
[m,n,p] = size(A) ;
NewestA = zeros(m,N,p) ;
yi = linspace(1,m,N);
for g = 1:n
for h =1:p
R=interp1(1:m,A(:,g,h),yi);
NewestA(:,g,h) = R;
end
end
A=NewestA

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

추가 답변 (1개)

Matt J
Matt J 2019년 3월 22일
편집: Matt J 2019년 3월 22일
Using my KronProd class (Download)
m=14; p=221; A = rand(m,m,p) ;
M=40; %new XY dimension
B=interp1(eye(m),linspace(1,m,M),'spline' );
A_upsampled=KronProd({B,1},[1,1,2],[nan,nan, p])*A;

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by