Vectorizing pairwise linear interpolation
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hey everyone,
I'm having some trouble vectorizing the code below for better performance:
for k = 1:n
intMat(k, :) = interp1(theta, data(:,:,k), angle_obs(k));
end
Basically, I have a 3D array of data, the first dimension corresponds to the variation with theta, the second dimension corresponds to the variation with frequency (not relevant here), and the third dimension corresponds to the various observations made. I need to interpolate the data of each observation with the corresponding observed angle (angle_obs), and get a matrix with the variation of theta for each observation.
My current implementation which performs a bit better is below:
auxMat = interp1(theta, data, angle_obs);
for k = 1:n
intMat(k, :) = auxMat(k, :, k);
end
But still, the interp1 function is calculating every pairwise interpolation, when all I need are the ones where the observation matches the respective angle_obs, so my for loop is keeping only the entries on the 1-3 "diagonal" of the array returned by interp1 (by the way, is there any way to vectorize this part of taking the diagonal entries?).
Is there anyway to vectorize what I intend to do? basically, use some sort of interp function that allows me to specify that I want it to calculate only the matching entries?
Thanks in advance
PS: I also posted this in the Newsgroup, don't know which place is more adequate, feel free to delete the inadequate one.
0 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!