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

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