Load the sample data.

load fisheriris

The column vector, `species`, consists of iris
flowers of three different species, setosa, versicolor, virginica.
The double matrix `meas` consists of four types of
measurements on the flowers, the length and width of sepals and petals
in centimeters, respectively.

Store the data in a table array.

t = table(species,meas(:,1),meas(:,2),meas(:,3),meas(:,4),...
'VariableNames',{'species','meas1','meas2','meas3','meas4'});
Meas = dataset([1 2 3 4]','VarNames',{'Measurements'});

Fit a repeated measures model, where the measurements
are the responses and the species is the predictor variable.

rm = fitrm(t,'meas1-meas4~species','WithinDesign',Meas);

Compute the marginal means grouped by the factor species.

margmean(rm,'species')

ans =
species Mean StdErr Lower Upper
____________ ______ ________ ______ ______
'setosa' 2.5355 0.042807 2.4509 2.6201
'versicolor' 3.573 0.042807 3.4884 3.6576
'virginica' 4.285 0.042807 4.2004 4.3696

`StdError` field shows the standard errors
of the estimated marginal means. The `Lower` and `Upper` fields
show the lower and upper bounds for the 95% confidence intervals of
the group marginal means, respectively. None of the confidence intervals
overlap, which indicates that marginal means differ with species.
You can also plot the estimated marginal means using the `plotprofile` method.

Compute the 99% confidence intervals for the marginal
means.

margmean(rm,'species','alpha',0.01)

ans =
species Mean StdErr Lower Upper
____________ ______ ________ ______ ______
'setosa' 2.5355 0.042807 2.4238 2.6472
'versicolor' 3.573 0.042807 3.4613 3.6847
'virginica' 4.285 0.042807 4.1733 4.3967