MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
D = 1x3 categorical array
+ blue - red + green

categories(D)

ans = 6x1 cell array
{'+ blue' }
{'+ green'}
{'+ red' }
{'- blue' }
{'- green'}
{'- red' }

Multiplication with Undefined Elements

Combine two categorical arrays. If either A or B have an undefined element, the
corresponding element of C is undefined.

A = categorical({'blue','red','green','black'});
B = categorical({'+','-','+','-'});
A = removecats(A,{'black'});
C = A.*B

C = 1x4 categorical array
blue + red - green + <undefined>

Cartesian Product of Ordinal Categorical Arrays

Combine two ordinal categorical arrays. C is an ordinal categorical array only if A and B
are both ordinal. The ordering of the categories of C follows from the orderings of the
input categorical arrays.

A = categorical({'blue','red','green'},{'green','red','blue'},'Ordinal',true);
B = categorical({'+','-','+'},'Ordinal',true);
C = A.*B;
categories(C)

ans = 6x1 cell array
{'green +'}
{'green -'}
{'red +' }
{'red -' }

8 Categorical Arrays

Free download pdf