Create Categorical Array with Different Categories
Create a categorical array, Group2, containing data from 50 students who were given the additional
beverage option of soda.
Group2 = randi(4,[50,1]);
Group2 = categorical(Group2,1:4,{'juice' 'milk' 'soda' 'water'});
Summarize the categorical array, Group2.
summary(Group2)
juice
12
milk
14
soda
10
water
14
Group2 is a 50-by-1 categorical array with four categories: juice, milk, soda, and water.
Concatenate Arrays with Different Categories
Concatenate the data from Group1 and Group2.
students = [Group1;Group2];
Summarize the resulting categorical array, students.
summary(students)
milk
29
water
27
juice
37
soda
10
Concatenation appends the categories exclusive to the second input, soda, to the end of the list of
categories from the first input, milk, water, juice, soda.
Use reordercats to change the order of the categories in the categorical array, students.
students = reordercats(students,{'juice','milk','water','soda'});
categories(students)
ans = 4x1 cell
{'juice'}
{'milk' }
{'water'}
{'soda' }
Union of Categorical Arrays
Use the function union to find the unique responses from Group1 and Group2.
C = union(Group1,Group2)
C = 4x1 categorical
milk
water
8 Categorical Arrays
8-20
Précédent

- 324/1450

Suivant