How do I interpolate to get the y axis values when I sub in the x axis values? My data is like a plot with no function associated to it.
5 次查看(过去 30 天)
显示 更早的评论
I have a set of data points (an array, column 1 is for x values and column 2 is for y values) and I want to be able to sub in x values (not part of the initial data points) to get the y values based on interpolation of the current data points I have.
For example I have data for x values [1,3,5,6] and these x values map to y values of [2,4,6,8] but I want to be able to input x value 2 and get a y value based on the interpolation.
How can I do interpolation with a vector set of data like:
final_list(:,1) = x axis values
final_list(:,2) = y axis values
The cubic line from the tools is not able to give me a "best fit curve" hence I cannot use the equation as such. Any ideas how I can use interpolation function from matlab or am I looking at the wrong documentation?
Thanks in advance for any help/advise given!
2 个评论
Mathieu NOE
2022-3-3
编辑:Mathieu NOE
2022-3-3
hello
sorry, your request is a bit unclear to me. Do you want to interpolate, curve fit or ???
seems the cubic polynomial fit is doing a good job so what is the issue ?
maybe a piece of code + a picture of what you want is appropriate
采纳的回答
Star Strider
2022-3-3
After first creating ‘FinalList’ as a table and writing it to a file:
FinalList = array2table(final_list_2_5, 'VariableNames',{'ROC','V','Delta_e','Gamma','AOA','H'});
pth = pwd;
writetable(FinalList, fullfile(pwd,sprintf('FinalList PS=%.1f.txt',PS)))
fprintf('\nTable written to: %s\n',fullfile(pwd,sprintf('FinalList PS=%.1f.txt',PS)))
Try this —
FinalList = readtable('FinalList PS=2.5.txt');
% ------ Plotting graph ------ %
figure % Elevator deflection vs altitude for PS = 2.5
plot(FinalList{:,6},FinalList{:,2})
hold on
Alt = [70, 1111, 4225, 6789, 8030];
ElevDefl = @(Alt) interp1(FinalList{:,6}, FinalList{:,2}, Alt); % Interpolate
plot(Alt, ElevDefl(Alt), 'sr')
hold off
xlabel('Altitude')
ylabel('Elevator Deflection')
title('Elevator settings for each altitude at Power setting = 2.5')
legend('PS = 2.5')
.
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!