Combine Categorical Arrays
This example shows how to combine two categorical arrays.
Create Categorical Arrays
Create a categorical array, A, containing the preferred lunchtime beverage of 25 students
in classroom A.
A = gallery('integerdata',3,[25,1],1);
A = categorical(A,1:3,{'milk' 'water' 'juice'});
A is a 25-by-1 categorical array with three distinct categories: milk, water, and juice.
Summarize the categorical array, A.
summary(A)
milk 8
water 8
juice 9
Eight students in classroom A prefer milk, eight prefer water, and nine prefer juice.
Create another categorical array, B, containing the preferences of 28 students in
classroom B.
B = gallery('integerdata',3,[28,1],3);
B = categorical(B,1:3,{'milk' 'water' 'juice'});
B is a 28-by-1 categorical array containing the same categories as A.
Summarize the categorical array, B.
summary(B)
milk 12
water 10
juice 6
Twelve students in classroom B prefer milk, ten prefer water, and six prefer juice.
Concatenate Categorical Arrays
Concatenate the data from classrooms A and B into a single categorical array, Group1.
Combine Categorical Arrays