Navigate to the folder containing sample data.

cd(matlabroot)
cd('help/toolbox/stats/examples')

Load the sample data.

load('longitudinalData')

The matrix `Y` contains response data for 16
individuals. The response is the blood level of a drug measured at
five time points (time = 0, 2, 4, 6, and 8). Each row of `Y` corresponds
to an individual, and each column corresponds to a time point. The
first eight subjects are female, and the second eight subjects are
male. This is simulated data.

Define a variable that stores gender information.

Gender = ['F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'M' 'M' 'M' 'M' 'M' 'M' 'M' 'M']';

Store the data in a proper table array format to do repeated
measures analysis.

t = table(Gender,Y(:,1),Y(:,2),Y(:,3),Y(:,4),Y(:,5),...
'VariableNames',{'Gender','t0','t2','t4','t6','t8'});

Define the within-subjects variable.

Time = [0 2 4 6 8]';

Fit a repeated measures model, where the blood levels
are the responses and gender is the predictor variable.

rm = fitrm(t,'t0-t8 ~ Gender','WithinDesign',Time);

Perform repeated measures analysis of variance.

ranovatbl = ranova(rm)

ranovatbl =
SumSq DF MeanSq F pValue pValueGG pValueHF pValueLB
______ __ ______ _______ __________ __________ __________ __________
(Intercept):Time 881.7 4 220.43 37.539 3.0348e-15 4.7325e-09 6.2859e-11 2.6198e-05
Gender:Time 17.65 4 4.4125 0.75146 0.56126 0.4877 0.515 0.40063
Error(Time) 328.83 56 5.872

There are 5 time points, 2 genders, and 16 observations. So,
the degrees of freedom for time is (5–1) = 4, for gender-time
interaction it is (5–1)*(2–1) = 4, and for error it
is (16–2)*(5–1) = 56. The small *p*-value
of 2.6198e–05 indicates that there is a significant effect
of time on blood pressure. The *p* -value of 0.40063
indicates that there is no significant gender-time interaction.