While using fit function, how to make sure the generated fit is only of the range of data points ?

11 次查看(过去 30 天)
I have 6 datapoints and I generated a fit but the the fit exceeds the range of my datapoints. I have attached an image to show it.
I have also attached my code, please let me know what options to choose to make sure that my git is exactly of the range of my datapoints.
%% fitting a cateanry curve equation
l = 1.76; % physical length of catenary curve
fun = @(c) (- l/2 + c * sinh(x_bar/(2*c))); x0 = 0.15;
c = abs(fzero(fun,x0)); % computes value of parameter a (sag)
xx = xy0(1,:) % from dataset
yy = xy0(2,:)
ft = fittype('a*cosh((x)./a)+b', 'problem','a') % b is the coefficient used by fit and it optimises b
[f, gof]=fit(xx(:), yy(:),ft,'problem', c)
  1 个评论
Matt J
Matt J 2023-7-21
编辑:Matt J 2023-7-21
I have attached an image to show it.
I for one don't understand what the image is supposed to show. The fit looks pretty good, and its plot covers the same range of x values as the data shown there.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2023-7-21
A fit does not have an inherent "range". Once the fit is computed, you can plot it over any range of x values that you wish, e.g.,
xp=linspace(min(xx(:)) , max(xx(:)));
plot(xp,f(xp))

更多回答(1 个)

the cyclist
the cyclist 2023-7-21
If you only supply 6 data points to the fitting function, it will only use those points. MATLAB doesn't "know" to do anything else.
But, that function still exists for all other points besides what was used to fit it. So, MATLAB can still plot it elsewhere. If you prefer not to plot beyond the range of the fitted points, then you can use the xlim function to limit where you plot.

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by