List the categories of Location, as well as the number of elements in each category.
summary(Location)
County General Hospital
39
St. Mary's Medical Center
24
VA Hospital
0
The patients observed at VA Hospital are deleted from Location, but VA Hospital is still a
category.
Use the removecats function to remove VA Hospital from the categories of Location.
Location = removecats(Location,'VA Hospital');
Verify that the category, VA Hospital, was removed.
categories(Location)
ans = 2x1 cell
{'County General Hospital' }
{'St. Mary's Medical Center'}
Location is a 63-by-1 categorical array that has two categories.
Delete Element
You can delete elements by indexing. For example, you can remove the first element of Location by
selecting the rest of the elements with Location(2:end). However, an easier way to delete
elements is to use [].
Location(1) = [];
summary(Location)
County General Hospital
38
St. Mary's Medical Center
24
Location is a 62-by-1 categorical array that has two categories. Deleting the first element has no
effect on other elements from the same category and does not delete the category itself.
Check for Undefined Data
Remove the category County General Hospital from Location.
Location = removecats(Location,'County General Hospital');
Display the first eight elements of the categorical array, Location.
Location(1:8)
ans = 8x1 categorical
St. Mary's Medical Center
St. Mary's Medical Center
St. Mary's Medical Center
St. Mary's Medical Center
Access Data Using Categorical Arrays
8-27
summary(Location)
County General Hospital
39
St. Mary's Medical Center
24
VA Hospital
0
The patients observed at VA Hospital are deleted from Location, but VA Hospital is still a
category.
Use the removecats function to remove VA Hospital from the categories of Location.
Location = removecats(Location,'VA Hospital');
Verify that the category, VA Hospital, was removed.
categories(Location)
ans = 2x1 cell
{'County General Hospital' }
{'St. Mary's Medical Center'}
Location is a 63-by-1 categorical array that has two categories.
Delete Element
You can delete elements by indexing. For example, you can remove the first element of Location by
selecting the rest of the elements with Location(2:end). However, an easier way to delete
elements is to use [].
Location(1) = [];
summary(Location)
County General Hospital
38
St. Mary's Medical Center
24
Location is a 62-by-1 categorical array that has two categories. Deleting the first element has no
effect on other elements from the same category and does not delete the category itself.
Check for Undefined Data
Remove the category County General Hospital from Location.
Location = removecats(Location,'County General Hospital');
Display the first eight elements of the categorical array, Location.
Location(1:8)
ans = 8x1 categorical
St. Mary's Medical Center
St. Mary's Medical Center
St. Mary's Medical Center
St. Mary's Medical Center
Access Data Using Categorical Arrays
8-27
