Interpolation with interp1 and matrix

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 日

0 投票

%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.

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

製品

リリース

R2016a

質問済み:

2022 年 4 月 12 日

編集済み:

2022 年 4 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by