最佳拟合散点图线

发布于 2024-08-17 07:32:59 字数 157 浏览 2 评论 0原文

我正在尝试在 matlab 中用最适合的线绘制散点图,我可以使用 scatter(x1,x2) 或 scatterplot(x1,x2) 获得散点图,但基本拟合选项被遮蔽并且 lsline 返回错误“未找到允许的线类型。什么也没做'

任何帮助都会很棒,

谢谢, 乔恩.

I'm trying to do a scatter plot with a line of best fit in matlab, I can get a scatter plot using either scatter(x1,x2) or scatterplot(x1,x2) but the basic fitting option is shadowed out and lsline returns the error 'No allowed line types found. Nothing done'

Any help would be great,

Thanks,
Jon.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

勿挽旧人 2024-08-24 07:32:59

lsline 仅可用统计工具箱里有统计工具箱吗?更通用的解决方案可能是使用polyfit

您需要使用 polyfit 使数据适合一条线。假设您在 y 中有一些数据,并且在 x 中有相应的域值(即,您有近似于 y = f(x) 的数据任意 f),那么您可以按如下方式拟合线性曲线:

p = polyfit(x,y,1);   % p returns 2 coefficients fitting r = a_1 * x + a_2
r = p(1) .* x + p(2); % compute a new vector r that has matching datapoints in x

% now plot both the points in y and the curve fit in r
plot(x, y, 'x');
hold on;
plot(x, r, '-');
hold off;

请注意,如果您想将任意多项式拟合到数据中,您可以通过将 polyfit 的最后一个参数更改为该数据的维数来实现曲线拟合。假设我们将此维度称为 d,您将收到 p 中的 d+1 系数,它表示符合 < 估计值的多项式code>f(x):

f(x) = p(1) * x^d + p(2) * x^(d-1) + ... + p(d)*x + p(d+1)

编辑,如评论中所述,您也可以使用 polyval 来计算 r,其语法如下:

r = polyval(p, x);

lsline is only available in the Statistics Toolbox, do you have the statistics toolbox? A more general solution might be to use polyfit.

You need to use polyfit to fit a line to your data. Suppose you have some data in y and you have corresponding domain values in x, (ie you have data approximating y = f(x) for arbitrary f) then you can fit a linear curve as follows:

p = polyfit(x,y,1);   % p returns 2 coefficients fitting r = a_1 * x + a_2
r = p(1) .* x + p(2); % compute a new vector r that has matching datapoints in x

% now plot both the points in y and the curve fit in r
plot(x, y, 'x');
hold on;
plot(x, r, '-');
hold off;

Note that if you want to fit an arbitrary polynomial to your data you can do so by changing the last parameter of polyfit to be the dimensionality of the curvefit. Suppose we call this dimension d, you'll receive back d+1 coefficients in p, which represent a polynomial conforming to an estimate of f(x):

f(x) = p(1) * x^d + p(2) * x^(d-1) + ... + p(d)*x + p(d+1)

Edit, as noted in a comment you can also use polyval to compute r, its syntax would like like this:

r = polyval(p, x);
时间海 2024-08-24 07:32:59

Infs、NaN 和复数的虚部在数据中被忽略。

曲线拟合工具提供了灵活的图形用户界面,您可以在其中交互式地将曲线和曲面拟合到数据和视图图。您可以:

创建、绘制和比较多个拟合

使用线性或非线性回归、插值、局部平滑回归或自定义方程

查看拟合优度统计数据、显示置信区间和残差、删除异常值并使用验证数据评估拟合

自动生成代码拟合和绘制曲面,或将拟合导出到工作区以进行进一步分析

Infs, NaNs, and imaginaryparts of complex numbers are ignored in the data.

Curve Fitting Tool provides a flexible graphical user interfacewhere you can interactively fit curves and surfaces to data and viewplots. You can:

Create, plot, and compare multiple fits

Use linear or nonlinear regression, interpolation,local smoothing regression, or custom equations

View goodness-of-fit statistics, display confidenceintervals and residuals, remove outliers and assess fits with validationdata

Automatically generate code for fitting and plottingsurfaces, or export fits to workspace for further analysis

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文