歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Matlab中用fit做曲線擬合

Matlab中用fit做曲線擬合

日期:2017/3/1 9:15:00   编辑:Linux編程

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.5426    0.0101    0.0003

4.獲取擬合優度

  現在已經獲得了擬合系數,那到底擬合得怎麼樣呢?可以使用下面的格式獲取擬合優度

[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.htm

Matlab與C/C++聯合編程之從Matlab調用C/C++代碼 http://www.linuxidc.com/Linux/2012-08/68148.htm

二分類SVM方法Matlab實現 http://www.linuxidc.com/Linux/2013-05/84050.htm

Matlab中的取整函數fix, floor, ceil與round http://www.linuxidc.com/Linux/2013-10/91161.htm

Matlab編譯cuda的.cu文件 http://www.linuxidc.com/Linux/2014-04/100675.htm

Linux Matlab服務器進一步改造成Application Server(應用程序服務器) http://www.linuxidc.com/Linux/2014-09/106340.htm

Matlab 坐標圖動畫,動態顯示數據 http://www.linuxidc.com/Linux/2016-03/129056.htm

Ubuntu 14.04安裝Matlab2012a過程 http://www.linuxidc.com/Linux/2015-12/126297.htm

Copyright © Linux教程網 All Rights Reserved