Interpolation with interp1 and matrix

3 次查看(过去 30 天)
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 个评论
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