Interpolation with interp1 and matrix

조회 수: 6 (최근 30일)
Francesc
Francesc 2022년 4월 12일
편집: Matt J 2022년 4월 12일
Hello,
I have a signal of 25,000 points recorded for several pixels (1,600). Each of the pixels have an associated grid of 25,000 points. I would like to perform a "pchip" interpolation of my signal to a new common grid for all pixels with a length of 20,000 and without a for loop. I have tried with interp1 (common grid and signal with dimensions 1,600 x 25,000; common grid with dimension 1 x 20,000) but it does not work without a for loop because to each pixel there is a different associated grid. I believe the approach would work if the original grid was common for all pixels.
Could you help me with that? Is there an alternative without a for loop?
Thanks in advance,
Francesc
  댓글 수: 2
KSSV
KSSV 2022년 4월 12일
Whats wrong in using loop?
Francesc
Francesc 2022년 4월 12일
편집: Francesc 2022년 4월 12일
I already have several loops on top, as I am analysing massive amounts of data. Therefore, I need to speed up every bit of code I have.

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

답변 (1개)

Matt J
Matt J 2022년 4월 12일
편집: Matt J 2022년 4월 12일
%example data
x=sort(rand(25000,1600),1); %grids per pixel
v=rand(size(x)); %signals
xq=sort(rand(20000,1)); %common grid;
%loop method
tic;
xnew=nan(20000,1600);
for i=1:size(x,2)
xnew(:,i)=interp1(x(:,i),v(:,i),xq,'pchip');
end
toc
Elapsed time is 1.937708 seconds.
%loop-free method
tic;
increm=cumsum( max(x(:,1:end-1),[],1)+1 );
x(:,2:end)=x(:,2:end)+increm;
xq=[xq,xq+increm];
xnew=interp1(x(:),v(:),xq(:),'pchip');
toc;
Elapsed time is 3.196412 seconds.

카테고리

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

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by