YXHJ513
YXHJ513

Reputation: 100

Linear regression model in Matlab

I have a linear regression prbolem at hand to solve, and I have found that this Matlab function mdl = fitlm(X, y) can do that. Then the new problem occured: after knowing about the usage of this function, I can't use this function in my Matlab R2013a. It always says Undefined function or variable 'fitlm'.

I think this may be due to some settings having not been done, but I am not familiar with Matlab. Can you help me?

Upvotes: 0

Views: 4864

Answers (2)

Andrey Rubshtein
Andrey Rubshtein

Reputation: 20915

polyfit with n=1 should do the trick.

p = polyfit(x,y,1);

Upvotes: 1

Taj Morton
Taj Morton

Reputation: 1638

I don't think fitlm() is available in R2013a, unfortunately. You can check if you have the Statistics Toolbox by running the ver command, and use the exist command to check if fitlm() is available:

>> ver
-----------------------------------------------------------------------
MATLAB Version: 8.0.0.783 (R2012b)
...
Stateflow                                             Version 8.0        (R2012b)
Statistics Toolbox                                    Version 8.1        (R2012b)
Symbolic Math Toolbox                                 Version 5.9        (R2012b)
...

>> exist fitlm
ans =
     0

That said, if fitlm() isn't available, try using the LinearModel.fit instead: http://www.mathworks.com/help/stats/linearmodel.fit.html

It looks like it might do exactly what you need!

Upvotes: 1

Related Questions