最佳拟合散点图线
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
lsline
仅可用统计工具箱里有统计工具箱吗?更通用的解决方案可能是使用polyfit
。您需要使用
polyfit
使数据适合一条线。假设您在y
中有一些数据,并且在x
中有相应的域值(即,您有近似于y = f(x)
的数据任意f
),那么您可以按如下方式拟合线性曲线:请注意,如果您想将任意多项式拟合到数据中,您可以通过将 polyfit 的最后一个参数更改为该数据的维数来实现曲线拟合。假设我们将此维度称为
d
,您将收到p
中的d+1
系数,它表示符合 < 估计值的多项式code>f(x):编辑,如评论中所述,您也可以使用
polyval
来计算r
,其语法如下:lsline
is only available in the Statistics Toolbox, do you have the statistics toolbox? A more general solution might be to usepolyfit
.You need to use
polyfit
to fit a line to your data. Suppose you have some data iny
and you have corresponding domain values inx
, (ie you have data approximatingy = f(x)
for arbitraryf
) then you can fit a linear curve as follows: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 backd+1
coefficients inp
, which represent a polynomial conforming to an estimate off(x)
:Edit, as noted in a comment you can also use
polyval
to computer
, its syntax would like like this: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