2015-10-20 109 views
1

正如標題所示,我在Matlab中使用「fitlm」,它工作得很好。當我運行的代碼,估計係數寫出這樣的:如何保存從fitlm中獲得的估計係數MATLAB

mdl1 = 


Linear regression model: 
    y ~ 1 + x1 

Estimated Coefficients: 
        Estimate  SE  tStat  pValue 
        ________ _________ ______ ______ 

    (Intercept) 2.1999  0.0043976 500.25 0  
    x1    591.68  0.31096 1902.8 0  


Number of observations: 24800, Error degrees of freedom: 24798 
Root Mean Squared Error: 0.693 
R-squared: 0.993, Adjusted R-Squared 0.993 
F-statistic vs. constant model: 3.62e+06, p-value = 0 

我怎樣才能將這些數據保存到文件或表?

感謝

回答

1

您可以從您的fitlm對象訪問Coefficients場和檢索Estimate領域得到係數:

下面是一個使用hald數據集在MATLAB的例子:

>> load hald; 
>> lm = fitlm(ingredients,heat) 

lm = 


Linear regression model: 
    y ~ 1 + x1 + x2 + x3 + x4 

Estimated Coefficients: 
        Estimate  SE  tStat  pValue 
        ________ _______ ________ ________ 

    (Intercept)  62.405  70.071  0.8906  0.39913 
    x1    1.5511 0.74477  2.0827 0.070822 
    x2    0.51017 0.72379  0.70486  0.5009 
    x3    0.10191 0.75471  0.13503  0.89592 
    x4    -0.14406 0.70905 -0.20317  0.84407 

>> lm.Coefficients.Estimate 

ans = 

    62.4054 
    1.5511 
    0.5102 
    0.1019 
    -0.1441 
+1

謝謝,它工作正常! =) – Elin

+0

@Elin很高興它!祝你好運! – rayryeng

相關問題