2016-04-27 68 views
1

加载后,预先拟合的曲面(sfit)模型如下图所示。从sfit对象获取平均值和std

问题:如何从sfit对象中获取x/y数据的精确平均值/标准偏差(而不是通过繁琐的输出复制)?

备注:

  1. 我能够通过调用其API的coeffnames/coeffvalues让所有的系数。然而,似乎没有类似的平均值/标准API。
  2. sfit模型适合的原始数据目前无法访问。所以the method依靠原始数据是不适用的。

enter image description here

回答

2

综观sfit类的源,事实证明,所述平均值和标准偏差被存储在private属性meanxmeanystdxstdy。事实上,这些是private使工作不平凡,但thanks to Yair Altman we know that呼吁struct()上课通常显示其所有善良。

使用来自sfit documentation稍加修改的例子,

x = 3 - 6 * rand(49, 1); 
y = 3 - 6 * rand(49, 1); 
z = peaks(x, y); 
sf = fit([x, y], z, 'poly32', 'normalize', 'on'); 

这里就是我们看到:

>> sf 

    Linear model Poly32: 
    sf(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p30*x^3 + 
        p21*x^2*y + p12*x*y^2 
     where x is normalized by mean -0.3736 and std 1.887 
     and where y is normalized by mean -0.04893 and std 1.644 
    Coefficients (with 95% confidence bounds): 
     p00 =  0.4227 (-0.3731, 1.218) 
     p10 =  1.764 (0.5627, 2.965) 
     p01 =  1.313 (0.7715, 1.855) 
     p20 =  -0.1054 (-0.6496, 0.4389) 
     p11 =  0.4627 (0.03944, 0.8859) 
     p02 =  0.1898 (-0.2443, 0.6239) 
     p30 =  -0.6345 (-1.247, -0.02209) 
     p21 =  -0.8263 (-1.32, -0.3327) 
     p12 =  -0.4908 (-1.011, 0.02911) 

>> sf_struct=struct(sf) 
Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be avoided. Use DISP or 
DISPLAY to see the visible public details of an object. See 'help struct' for more information. 

    sf_struct = 

       version: 2 
      fCoeffValues: {[0.4227] [1.7639] [1.3130] [-0.1054] [0.4627] [0.1898] [-0.6345] [-0.8263] [-0.4908]} 
      fProbValues: {1x0 cell} 
        sse: 59.5574 
        dfe: 40 
        rinv: [9x9 double] 
      activebounds: [9x1 logical] 
        meanx: -0.3736 
        meany: -0.0489 
        stdx: 1.8875 
        stdy: 1.6441 
        xlim: [-2.8236 2.8090] 
        ylim: [-2.7585 2.6763] 
        fType: 'poly32' 
       fTypename: 'Poly32' 
       fCategory: 'library' 
        defn: 'p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p30*x^3 + p21*x^2*y + p12*x*y^2' 
        fFeval: 1 
        expr: @polySurface 
        Adefn: {} 
        Aexpr: {} 
        linear: 1 
       derexpr: @polySurfaceDerivative 
       intexpr: [] 
        args: [11x3 char] 
       isEmpty: 0 
       numArgs: 11 
       numCoeffs: 9 
      assignCoeff: [1x234 char] 
       assignData: ' x = FITTYPE_INPUTS_{10}; y = FITTYPE_INPUTS_{11};' 
       assignProb: '' 
        indep: [2x1 char] 
        depen: 'z' 
        coeff: [9x3 char] 
        prob: '' 
       fConstants: {[3] [2]} 
     fNonlinearcoeffs: [] 
      fFitoptions: [1x1 curvefit.llsqoptions] 
       fStartpt: [] 

>> [sf_struct.meanx, sf_struct.meany, sf_struct.stdx, sf_struct.stdy] 

    ans = 

     -0.3736 -0.0489 1.8875 1.6441 

至少在R2012b上述作品。

+1

'struct'很神奇!非常感谢。 :d – herohuyongtao