MATLAB: No appropriate method ‘TOCObj’ for class ‘mlreportg​en.report.​TableOfCon​tents’.

MATLABMATLAB Report Generatortabletable of contents

Hello, I am trying to customize my table of contents in my report as presented the mlreportgen.report.TableOfContents class documentation. However I get an error when I do this
toc = TableOfContents;
toc.TOCObj.NumberOfLevels = 2;
add(rpt, toc);
The error is:
No appropriate method, property, or field 'TOCObj' for class 'mlreportgen.report.TableOfContents'.
Error in Mreport (line 92)
toc.TOCObj.NumberOfLevels = 2;
Has the TOCObj been removed from Matlab or does the error come from somewhere else?
Thank you in advance!

Best Answer

I think you are using MATLAB R2018a version. But the example you are referring is from documentation of R2019a version (which supports the feature of specifying number of levels). The feature to programmatically specify the number of TOC levels is added in R2018b version.
Since you are using MATLAB R2018a, the error is being created (TOCObj is not supported in versions prior to R2018b). Try using MATLAB R2018b or R2019a.
You may refer Enhanced table of contents customization in the following link