Interpolating data in 1D with 2D sample points and a 2D matrix

조회 수: 14 (최근 30일)
Jose Luis Villaescusa Nadal
Jose Luis Villaescusa Nadal 2022년 12월 5일
답변: Vijay 2022년 12월 30일
I have a matrix of Temperatures ( T - [120xN] ) at different heights ( H - [120xN] ). I want to obtain the Temperatures at a set vector of heights ( Hnew - [100x1] ], where N is the total number of lines I want to independently interpolate in 1D.
I can solve this with a loop quite easily
Tnew = zeros(length(Hnew),N);
for i-1:N
Tnew(:,i) = interp1(H(:,i),T(:,i),Hnew);
end
But since I have many iterations to perform (N ~ 2 million), I am looking for a solution without a loop.
What is the optimum way to do this?

채택된 답변

Vijay
Vijay 2022년 12월 30일
The use of loop does not create any performance disadvantage. The bottleneck is the interpolation part. If your computer has large number of cores, >4, then you can utilize parfor pragma to parallelize your loop.
Tnew = zeros(length(Hnew),N);
parfor
for i-1:N
Tnew(:,i) = interp1(H(:,i),T(:,i),Hnew);
end
Please use the link below for more information
Hope that helps

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by