Quick data interpolation command
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!