mycrosstab
Takes 2 vectors of equal size and determines their cross-tabulation.
All input data must be real, positive integers.
Problem of built-in 'crosstab' function is that it does not take missing data into account. For example, given the data:
x y
1 0
1 1
1 1
2 0
2 1
4 0
4 0
This should give a contingency table of:
1 2
1 1
0 0 <- there is no data for x=3
2 0
However, the built-in function 'crosstab' would give the answer:
1 2
1 1
2 0
The function 'mycrosstab' uses 'crosstab' and then determines if any rows or columns are missing. If so, indices are added to the rows and columns and additional rows/columns with the appropriate indices are appended:
-1 0 1
1 1 2
2 1 1
4 2 0
3 0 0 <- additional column with index '3'
The rows and columns are then sorted so the indices are correctly ordered:
-1 0 1
1 1 2
2 1 1
3 0 0 <- additional column with index '3' now in appropriate place
4 2 0
The index row and column are then deleted, leaving a full cross-tabulation with all null rows and columns in the appropriate places:
1 2
1 1
0 0
2 0
Cite As
Lee Baker (2026). mycrosstab (https://www.mathworks.com/matlabcentral/fileexchange/28366-mycrosstab), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- AI and Statistics > Statistics and Machine Learning Toolbox > Descriptive Statistics and Visualization > Descriptive Statistics >
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 |
