Input the data.

strength = [82 86 79 83 84 85 86 87 74 82 ...
78 75 76 77 79 79 77 78 82 79];
alloy = {'st','st','st','st','st','st','st','st',...
'al1','al1','al1','al1','al1','al1',...
'al2','al2','al2','al2','al2','al2'};

The data are from a study of the strength of structural beams in Hogg (1987). The vector strength measures deflections of beams in thousandths of an inch under 3,000 pounds of force. The vector alloy identifies each beam as steel ('st'), alloy 1 ('al1'), or alloy 2 ('al2'). Although alloy is sorted in this example, grouping variables do not need to be sorted.

First perform one-way ANOVA.

[p,a,s] = anova1(strength,alloy);

The small *p* -value suggests that the strength of the beams is not the same.

Now, perform a multiple comparison of the mean strength of the beams.

[c,m,h,nms] = multcompare(s);

Display the comparison results with the corresponding group names.

[nms(c(:,1)), nms(c(:,2)), num2cell(c(:,3:6))]

ans =
'st' 'al1' [ 3.6064] [ 7] [10.3936] [1.6831e-04]
'st' 'al2' [ 1.6064] [ 5] [ 8.3936] [ 0.0040]
'al1' 'al2' [-5.6280] [-2] [ 1.6280] [ 0.3560]

The third row of the output matrix shows that the differences in strength between the two alloys is not significant. A 95% confidence interval for the difference is [-5.6, 1.6], so you cannot reject the hypothesis that the true difference is zero. This is also confirmed by the corresponding *p* -value of 0.3560 in the sixth column.

The first two rows show that both comparisons involving the first group (steel) have confidence intervals that do not include zero. And the corresponding *p* -values (1.6831e-04 and 0.0040, respectively) are small. In other words, those differences are significant. The graph shows the same information.