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.
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/913429/image.png)
2 commentaires
Mathieu NOE
le 3 Mar 2022
Modifié(e) : Mathieu NOE
le 3 Mar 2022
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
Réponse acceptée
Star Strider
le 3 Mar 2022
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Language Fundamentals dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!