time | Calls | line |
---|
| | 739 | function codes = castCodes(codes, numCats)
|
| | 740 | % CASTCODES picks an integer class that is capable of encoding 'numCats' many
|
| | 741 | % unique categories, and casts the input codes to that class.
|
| | 742 |
|
| | 743 | % Cast codes to the new class. This turns NaN in floating point (see e.g. min
|
| | 744 | % and max) into a 0 integer code (i.e. <undefined>).
|
| | 745 | %
|
| | 746 | % Number of categories is INTMAX(class) minus one to allow for an invalid
|
| | 747 | % code at the high end; except with UINT64, the limit is maximum array size
|
| | 748 | % allowed in MATLAB (i.e. categorical.maxNumCategories)
|
< 0.001 | 3 | 749 | if numCats <= 255-1 % intmax('uint8')-1
|
< 0.001 | 3 | 750 | codes = uint8(codes);
|
| | 751 | elseif numCats <= 65535-1 % intmax('uint16')-1
|
| | 752 | codes = uint16(codes);
|
| | 753 | elseif numCats <= 4294967295-1 % intmax('uint32')-1
|
| | 754 | codes = uint32(codes);
|
| | 755 | elseif numCats < categorical.maxNumCategories
|
| | 756 | codes = uint64(codes);
|
| | 757 | else % Error if exceeded maximum allowed number of categories
|
| | 758 | throwAsCaller(message('MATLAB:categorical:MaxNumCategoriesExceeded',categorical.maxNumCategories));
|
< 0.001 | 3 | 759 | end
|
< 0.001 | 3 | 760 | end
|
Other subfunctions in this file are not included in this listing.