This MATLAB documentation page gives a pretty comprehensive answer.
The following is my conclusion, assuming your samples are iid. (!), you do not have label noise (some samples have the wrong label), and you will not have much much more samples in application:
X = randn(300,18);
Y = X*randn(18,1) > 4; % use your data instead
cost=[0 100 ; 10 0]; % think seriously about these values. 100 is cost classifying a positive sample as negative and 10 the cost of the other error.
MinLeaf=length(Y)/2; %determines the individual tree size. the higher, the smaller are the trees. length(Y)/2 means only one split.
ens = fitensemble(X, Y, 'AdaBoostM1',nTrees,ClassificationTree.template('MinLeaf',MinLeaf),'nprint',1,'crossval','on','k',5,'cost',cost,'classnames',[true, false]);
hold on;hold all;
Use the graph to determine whether more trees would improve classification (look at the blue dots).
nTrees to increase or decrease model complexity. If your model is too static blue and red dots will overlap, if its is to complex training error will be zero. Find good values by ploting
MinLeaf. Note that you do not need to find the exact maximum; it will be noise anyway.
To improve classification find out whether more features or more samples will improve classification more by removing some of the existing and observing the effect (again using plots) and add more of them.
To get a final optimal classifier stop doing CV for training and use all the data you have. Get a new really independent test set if you want/need to report error rates. This is the only way to ensure unbiased errors, because as soon as you use a test set twice it is corrupted.
You could also use
Bag, use the oob error instead of CV, and vary
minleaf. Doesn't matter from my experience.