St. Mary's Medical Center
After removing the category, County General Hospital, elements that previously belonged to
that category no longer belong to any category defined for Location. Categorical arrays denote
these elements as undefined.
Use the function isundefined to find observations that do not belong to any category.
undefinedIndex = isundefined(Location);
undefinedIndex is a 62-by-1 categorical array containing logical true (1) for all undefined
elements in Location.
Set Undefined Elements
Use the summary function to print the number of undefined elements in Location.
summary(Location)
St. Mary's Medical Center
24
38
The first element of Location belongs to the category, St. Mary's Medical Center. Set the first
element to be undefined so that it no longer belongs to any category.
Location(1) = '';
summary(Location)
St. Mary's Medical Center
23
39
You can make selected elements undefined without removing a category or changing the categories
of other elements. Set elements to be undefined to indicate elements with values that are unknown.
Preallocate Categorical Arrays with Undefined Elements
You can use undefined elements to preallocate the size of a categorical array for better performance.
Create a categorical array that has elements with known locations only.
definedIndex = ~isundefined(Location);
newLocation = Location(definedIndex);
summary(newLocation)
St. Mary's Medical Center
23
Expand the size of newLocation so that it is a 200-by-1 categorical array. Set the last new element
to be undefined. All of the other new elements also are set to be undefined. The 23 original
elements keep the values they had.
newLocation(200) = '';
summary(newLocation)
St. Mary's Medical Center
23
177
8 Categorical Arrays
8-28
After removing the category, County General Hospital, elements that previously belonged to
that category no longer belong to any category defined for Location. Categorical arrays denote
these elements as undefined.
Use the function isundefined to find observations that do not belong to any category.
undefinedIndex = isundefined(Location);
undefinedIndex is a 62-by-1 categorical array containing logical true (1) for all undefined
elements in Location.
Set Undefined Elements
Use the summary function to print the number of undefined elements in Location.
summary(Location)
St. Mary's Medical Center
24
38
The first element of Location belongs to the category, St. Mary's Medical Center. Set the first
element to be undefined so that it no longer belongs to any category.
Location(1) = '
summary(Location)
St. Mary's Medical Center
23
39
You can make selected elements undefined without removing a category or changing the categories
of other elements. Set elements to be undefined to indicate elements with values that are unknown.
Preallocate Categorical Arrays with Undefined Elements
You can use undefined elements to preallocate the size of a categorical array for better performance.
Create a categorical array that has elements with known locations only.
definedIndex = ~isundefined(Location);
newLocation = Location(definedIndex);
summary(newLocation)
St. Mary's Medical Center
23
Expand the size of newLocation so that it is a 200-by-1 categorical array. Set the last new element
to be undefined. All of the other new elements also are set to be undefined. The 23 original
elements keep the values they had.
newLocation(200) = '
summary(newLocation)
St. Mary's Medical Center
23
177
8 Categorical Arrays
8-28
