Interpolation with interp1 and matrix
5 views (last 30 days)
Show older comments
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
Answers (1)
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
%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;
0 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!