필터 지우기
필터 지우기

Interpolation of 3D arrays against a 1D vector

조회 수: 3 (최근 30일)
Ahmad Gad
Ahmad Gad 2022년 8월 25일
댓글: Ahmad Gad 2022년 8월 25일
Hello all.
I have a video data represented as 3D matrix in the form of Data(x,y,t). Here, x,y represent the pixel number and t is the time. I have the time vector stored in a separate variable. I need to interpolate the variable Data at a new time vector represented by variable t_new to get the new variable Data_new(x,y,t_new). I am using the following code:
n = 20;
m = 60;
t = linspace(0,1,n)';
t_new = linspace(0,1,m)';
Data = rand(50,50,n);
Data_new = permute(interpn(t,permute(Data,[3 2 1]),t_new),[3 2 1]);
% Verification by plotting the time history of selected pixel:
x = 25;
y = 25;
plot(t,reshape(Data(x,y,:),n,1),t_new,reshape(Data_new(x,y,:),m,1))
It looks fine to me. but the main concerns I am asking about:
  1. I had to use permute twice. I am not able to do it without permute. Can I avoid this?
  2. Is there a faster method to perform this interpolation?
Thanks and best,
Ahmad

채택된 답변

Matt J
Matt J 2022년 8월 25일
편집: Matt J 2022년 8월 25일
[Nx,Ny,~]=size(Data);
F=griddedInterpolant({1:Nx,1:Ny,t},Data);
Data_new=F({1:Nx,1:Ny,t_new});
  댓글 수: 2
Ahmad Gad
Ahmad Gad 2022년 8월 25일
Thank you very much for the prompt response. That is very helpful.
Ahmad Gad
Ahmad Gad 2022년 8월 25일
Can you tell me why griddedInterpolant is nearly 5-6 times faster than interpn? Thanks!

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by