Quick data interpolation command
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2015-8-27
I don’t entirely understand what you’re doing, but the interp1 function will likely do what you want.
1 个评论
Stephen23
2015-8-27
All of MATLAB's interpolation functions can be found here:
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!