fit function to data

1 次查看(过去 30 天)
ignacio bobadilla tapia
Hello, please, if you could help me to fit a function to a data series, I understand that the matlab 'fit' function works excellent, but I don't know how to implement it. What I have to do is fit the best possible function to the data series, but the problem that I have two series 'x1' and 'x2', e 'y1' and 'y2', where they all go in a single figure, for which I write down the code I have. I attach the data. Thanks greetings.
load x1.txt , load x2.txt , load y1.txt , load y2.txt
plot(x1,y1,'or',x2,y2,'or')

回答(1 个)

Sulaymon Eshkabilov
load x1.txt , load x2.txt , load y1.txt , load y2.txt
plot(x1,y1,'or',x2,y2,'b*') % Differentiate different data sets while plotting them
FM1=fit(x1,y1,'poly2'); % Quadratic fit model
FM2=fit(x2,y2,'poly2'); % Quadratic fit model
...
  2 个评论
ignacio bobadilla tapia
I want all the data to be represented with only one function, that is, that x1 and x2 are the same matrix, and y1 and y2 are another matrix, then calculate the function. If you could help me please.
Walter Roberson
Walter Roberson 2021-6-25
x = [x1(:);x2(:)];
y = [y1(:);y2(:)];
FM = fit(x, y, 'poly2'); % Quadratic fit model
plot(FM, x)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Power and Energy Systems 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by