MATLAB: How to run the regression tree examle

fitrtreeregression

I tried to run the basic regression tree example in Matlab, I got the error message:
Undefined variable "RegressionTree" or class "RegressionTree.template".
Error in fitrtree (line 140) temp = RegressionTree.template(varargin{:});
Error in Testfile (line 6) tree = fitrtree([Weight, Cylinders],MPG,…
The code is from the Documentation "fitrtree" first example (<http://www.mathworks.com/help/stats/fitrtree.html)>, which is :
load carsmall;
tree = fitrtree([Weight, Cylinders],MPG,… 'categoricalpredictors',2,'MinParentSize',20,… 'PredictorNames',{'W','C'})

Best Answer

Strange. That code runs fine for me.
I assume you have the Statistics and Machine Learning Toolbox, otherwise you would have just gotten an error that fitrtree could not be found. Can you just confirm that, though? Do you see that toolbox when you type
ver
at the command line? Also, what does
which -all fitrtree
give as output?