Along the same lines as this question, is there a nice way to display regression results in MATLAB from a single or many regressions in table or graph form?

  • $\begingroup$ Download for free Spatial Econometrics TB by Le Sage. Nice and neat output may be obtained from therein. GT. $\endgroup$
    – leopino
    Commented May 14, 2011 at 9:34

3 Answers 3


In the (regrettably proprietary) system I have been working on, I set up linear regression as an object and overrode the display method. The output looks something like this:

lmetc = lm of:

       # obs: 100
    # params: 5
                    fac1      fac2      fac3      fac4
     betahat:      0.996   0.00696    0.0136   0.00845
   intercept:      -0.23
                    fac1      fac2      fac3      fac4
       tstat:     51.7!!   0.402     0.767     0.494  
intcpt tstat:    -12.5!!
      sighat:    0.1756 ci: (    0.154,     0.205)
         R^2:     0.967 ci: (     0.96,     0.974)
           F:       462 (df1 = 6, df2 = 94)
      F pval:         0
         AIC:     123.7
         BIC:     136.7

After the observations and parameters there is a row of the regression coefficients, which is easy to scan across. These are output with something like

display(sprintf('%12s : %s','betahat',sprintf('% 9.3g ',regression_parameters)));

Similarly, below that is a row of the t-statistics associated with each regression coefficient, possibly suffixed by a two character string (' *' for p-value < 0.05, ' !' for p-value < 0.01, etc.) Again, unfortunately you are on your own for this because Matlab does not have, outside the statistics tool-box, a cdf function for the t-distribution (I wrapped R's math library in a mex function. You can check the stats toolbox in octave-forge, perhaps.).

Below that is the estimate of $\sigma^2$, with a confidence interval (good luck getting Chi-square quantiles in vanilla Matlab), the $R^2$, and then the F statistic under the null hypothesis that all regression coefficients are zero, and finally the p-value for that (again, no F cdf in vanilla Matlab).

Unfortunately my answer seems to be: "the closed nature of Matlab makes this too difficult to do without money or effort or both, but here's a decent way to format the results once you've gotten past those hurdles." Sorry about that. good luck!


simply without using any toolbox box use "polyfit" and in consequence "polyval" function, here is the example : X could you you input data, and Y you response value or target value You can make a n-degree polynomial by :

  p = polyfit(x,y,n)

and fit the polynomial and get the interest output yd, based on fitted value.

  yd = polyval(p,xd);

the plot the data


If you check these functions help document, you would get more comprehensive information.

Also this documents talks about different types of regression and their implementation in Matlab


Here's some example code that might prove helpful.

I'm using the fit command from Curve Fitting Toolbox to perform the regression, but you could use regress, or regstats, or even backslash for the regression.

The display is using the "Dataset Array" from Statistics Toolbox. This is a data container designed to store heterogeneous data. In this case, I'm using it to store a combination of cell strings and doubles.

clear all

% Create a dataset array
Coeffs = {'B0'; 'B1'; 'B2'};
foo = dataset(Coeffs);

% Generate a dataset
X = 1:10;
X = X';
Y = 5*X.^2 + 3*X + 1;

% Add some noise
Noisy = Y + randn(10,1);

% Generate a fit
bar = fit(X,Noisy, 'poly2')

Model_One = [bar.p3;bar.p1; bar.p1];
foo.Model_One = Model_One

% Repeat
Noisy = Y + randn(10,1);
bar = fit(X,Noisy,'poly2');

Model_Two = [bar.p3;bar.p1; bar.p1];
foo.Model_Two = Model_Two;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.