Create two different normal probability distribution objects.
The first distribution has `mu = 0` and `sigma
= 1`. The second distribution has `mu = 2 ` and `sigma
= 1`.

pd1 = makedist('Normal');
pd2 = makedist('Normal','mu',2,'sigma',1);

Create a matrix of sample data by generating random numbers
from these two distributions.

rng('default'); % for reproducibility
x = [random(pd1,20,2),random(pd2,20,1)];

The first two columns of `x` contain data generated
from the first distribution, while the third column contains data
generated from the second distribution.

Test the null hypothesis that the sample data from each
column in `x` comes from the same distribution. Suppress
the output displays, and generate the structure `stats` to
use in further testing.

[p,tbl,stats] = kruskalwallis(x,[],'off')

p =
3.6896e-06
tbl =
Columns 1 through 4
'Source' 'SS' 'df' 'MS'
'Columns' [7.6311e+03] [ 2] [3.8155e+03]
'Error' [1.0364e+04] [57] [ 181.8228]
'Total' [ 17995] [59] []
Columns 5 through 6
'Chi-sq' 'Prob>Chi-sq'
[25.0200] [ 3.6896e-06]
[] []
[] []
stats =
gnames: [3x1 char]
n: [20 20 20]
source: 'kruskalwallis'
meanranks: [26.7500 18.9500 45.8000]
sumt: 0

The returned value of `p` indicates that the
test rejects the null hypothesis at the 1% significance level. You
can use the structure `stats` to perform additional
followup testing. The cell array `tbl` contains the
same data as the graphical ANOVA table, including column and row labels.

Conduct a followup test to identify which data sample
comes from a different distribution.

c = multcompare(stats)

Note: Intervals can be used for testing but are not simultaneous confidence intervals.
c =
1.0000 2.0000 -5.1435 7.8000 20.7435
1.0000 3.0000 -31.9935 -19.0500 -6.1065
2.0000 3.0000 -39.7935 -26.8500 -13.9065

The results indicate that there is a significant difference
between groups 1 and 3, so the test rejects the null hypothesis that
the data in these two groups comes from the same distribution. The
same is true for groups 2 and 3. However, there is not a significant
difference between groups 1 and 2, so the test does not reject the
null hypothesis that these two groups come from the same distribution.
Therefore, these results suggest that the data in groups 1 and 2 come
from the same distribution, and the data in group 3 comes from a different
distribution.