Interpolation with interp1 and matrix

5 views (last 30 days)
Francesc
Francesc on 12 Apr 2022
Edited: Matt J on 12 Apr 2022
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 Comments
KSSV
KSSV on 12 Apr 2022
Whats wrong in using loop?
Francesc
Francesc on 12 Apr 2022
Edited: Francesc on 12 Apr 2022
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.

Sign in to comment.

Answers (1)

Matt J
Matt J on 12 Apr 2022
Edited: Matt J on 12 Apr 2022
%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.

Categories

Find more on Interpolation in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!