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) = '<undefined>';
summary(newLocation)
St. Mary's Medical Center 23
<undefined> 177
newLocation has room for values you plan to store in the array later.
See Also
any | categorical | categories | histogram | isundefined | removecats |
summary
Related Examples
- “Create Categorical Arrays” on page 8-2
- “Convert Text in Table Variables to Categorical” on page 8-7
- “Plot Categorical Data” on page 8-12
- “Compare Categorical Array Elements” on page 8-20
- “Work with Protected Categorical Arrays” on page 8-38
8 Categorical Arrays