How to get curve fitting equation

4 次查看(过去 30 天)
Is there a way I can get the equation shwon in the figure or in the basic fitting window? The 8th degree polynimial.
I want to get this equation through a code line not through the graph tools, I also need it in the exact same form.(Including x)
I will repeiat this for a large number of plots or x and y data directly if possible.
Please ignore the red line at the bottom.
  2 个评论
akshatsood
akshatsood 2024-1-23
编辑:akshatsood 2024-1-23
Could you please provide me with the data needed to replicate the issue on my end, allowing me to assist you better?
Abdallah Magour
Abdallah Magour 2024-1-23
Hi Akshatsood thank you for your reply, yes I attached a data set in the excel file.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2024-1-23
编辑:Walter Roberson 2024-1-23
You would use polyfit
For a degree 8 polynomial, you would probably want to use the centering and scaling, by requesting that S and mu also be returned from polyfit()
To evaluate points at the fitted polynomial, see polyval
  6 个评论
Sam Chak
Sam Chak 2024-1-24
The data is not the same as what is shown in the image above. However, you can remove the NaN values by utilizing the isnan() function.
T = readtable("Data from a similar graph.xlsx", VariableNamingRule="preserve")
T = 17×2 table
x-axis y-axis _______ __________ -19.88 0.00013017 -14.923 NaN -9.8295 0.00034944 -4.7163 0.00010504 0.42855 0.00010026 5.4723 0.00010318 10.501 0.00010048 15.349 0.00010017 20.066 0.00010005 25.012 0.00010006 29.942 0.00010015 34.999 0.00010153 39.906 0.00010248 44.89 0.00010044 49.954 0.00010016 54.913 0.0001014
x = T{:,1};
y = T{:,2}; % contains NaN
data= [x, y];
%% Omit row contains NaN
data_clean = data(~isnan(data(:, 2)), :)
data_clean = 16×2
-19.8796 0.0001 -9.8295 0.0003 -4.7163 0.0001 0.4286 0.0001 5.4723 0.0001 10.5011 0.0001 15.3487 0.0001 20.0662 0.0001 25.0120 0.0001 29.9422 0.0001
%% Extract from clean data
x_clean = data(:,1);
y_clean = data(:,2);
plot(x_clean, y_clean, '-o'), grid on
Abdallah Magour
Abdallah Magour 2024-1-24
Hi Sam,
This is perfect,exactly what I needed!! Thank you very much.
Works much better than what I have.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by