首页 / 操作系统 / Linux / Matlab中用fit做曲线拟合
1.确定要拟合的类型 一般情况下matlab会直接提供常用的类型,用fittype创建拟合模型。至于matlab具体提供了哪些模型,参见帮助"List of library models for curve and surface fitting"ft = fittype( "gauss1" ); %高斯拟合2.要拟合的数据格式 在最简单的情况下,即拟合两个向量X,Y,则其必须是列向量3.拟合 使用fit进行拟合fitresult= fit( xData, yData, ft,); 其输出fitresult是一个cfit型的对象(object),主要包含两个内容:1,拟合模型,即第一步中确定的拟合类型;2,拟合所得系数的值。例如对第一步中所创建的高斯模型,其fitresult 的值为fitresult =General model Gauss1: fo(x) =a1*exp(-((x-b1)/c1)^2) Coefficients (with 95% confidence bounds): a1 = 45.54(42.45, 48.64) b1 = 0.01011(0.0101, 0.01012) c1 = 0.0002551(0.0002353, 0.0002748) 获得了这样一个object,如何把其中的系数提取出来呢?这个要用到coeffvalues函数>> coeffvalues(fitresult)ans = 45.54260.01010.00034.获取拟合优度 现在已经获得了拟合系数,那到底拟合得怎么样呢?可以使用下面的格式获取拟合优度[fitresult ,gof] = fit(X,Y,"gauss1"); gof是一个结构体,包含4个量sse:Sunm of squares due to error
rsquare:R-square 对这个就是线性回归里的那个R2,与线性回归里的具有同样的意义
dfe:Degrees of freedom in the error,不懂
adjrsquare: 也不懂
rmse: 误差的均方根值(rms) 嗯,暂时只需要用到这些,更高级的要用的时候再说。 Ubuntu Server上安装Matlab http://www.linuxidc.com/Linux/2014-09/106242.htmMatlab与C/C++联合编程之从Matlab调用C/C++代码 http://www.linuxidc.com/Linux/2012-08/68148.htm二分类SVM方法Matlab实现 http://www.linuxidc.com/Linux/2013-05/84050.htmMatlab中的取整函数fix, floor, ceil与round http://www.linuxidc.com/Linux/2013-10/91161.htmMatlab编译cuda的.cu文件 http://www.linuxidc.com/Linux/2014-04/100675.htmLinux Matlab服务器进一步改造成Application Server(应用程序服务器) http://www.linuxidc.com/Linux/2014-09/106340.htmMatlab 坐标图动画,动态显示数据 http://www.linuxidc.com/Linux/2016-03/129056.htmUbuntu 14.04安装Matlab2012a过程 http://www.linuxidc.com/Linux/2015-12/126297.htm本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-06/132208.htm