Interpolating data in 1D with 2D sample points and a 2D matrix
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jose Luis Villaescusa Nadal
le 5 Déc 2022
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?
0 commentaires
Réponse acceptée
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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!