www.gusucode.com > stats 源码程序 matlab案例代码 > stats/CrossTabulateIndependentDataVectorsExample.m

    %% Cross-Tabulate Independent Data Vectors

% Copyright 2015 The MathWorks, Inc.


%%
% Generate two independent vectors, |x1| and |x2|, each containing 50
% discrete uniform random numbers in the range |1:3|.
rng default;  % for reproducibility
x1 = unidrnd(3,50,1);
x2 = unidrnd(3,50,1);

%%
% Cross-tabulate |x1| and |x2|.
[table,chi2,p] = crosstab(x1,x2)

%%
% The returned |p| value of |0.1097| indicates that, at the 5% significance
% level, |crosstab| fails to reject the null hypothesis that |table| is
% independent in each dimension.