Effacer les filtres
Effacer les filtres

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

12 vues (au cours des 30 derniers jours)
Jose Luis Villaescusa Nadal
Réponse apportée : Vijay le 30 Déc 2022
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?

Réponse acceptée

Vijay
Vijay le 30 Déc 2022
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

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by