Quick data interpolation command
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I wanted to ask if there is any function developing a quick data interpolation, when already having a vector containing the grid of values to interpolate between. I have a vector of about 200 points, representing a certain function. Then I have another array, and I want to use them as values of the x-axes to interpolate through my 200 points grid which are values of the y-axes. At the moment I have built up a for loop that starts from the beginning of the x axes, finds all the values between two consecutive grid values, and makes a linea interpolation between the two points of the grid for all the identified points:
for i = 1:length(net)-1
j{i} = find(Pin >= net(i) & Pin < net(i+1));
m_main = (grid(i+1,1) - grid(i,1))/(net(i+1) - net(i));
q_main = grid(i+1,1) - m_main*net(i+1);
Pmain(j{i}) = m_main*Pin(j{i}) + q_main;
end
grid, is actually a matrix containing the y values (ordered), and net is the x coordinate for those values. I use pairs of consecutive values in order to compute the steepness of the linear conjunction between the two points, and the elevation. Then I simply modify all the values by the linear approximation with the classic y = m*x + q formula.
Now, since I seem to have some problems with my script (apparently changes the order of some data points in the final result), I was wondering if MATLAB is already offering some functions to obtain this quickly and properly.
Any tipp?
Best Regards, Giovanni
0 commentaires
Réponse acceptée
Star Strider
le 27 Août 2015
I don’t entirely understand what you’re doing, but the interp1 function will likely do what you want.
1 commentaire
Stephen23
le 27 Août 2015
All of MATLAB's interpolation functions can be found here:
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!