small 30
medium 35
large 35
Create Categorical Array from String Array
Starting in R2016b, you can create string arrays with the string function and convert
them to categorical array.
Create a string array that contains names of planets.
str = string({'Earth','Jupiter','Neptune','Jupiter','Mars','Earth'})
str = 1x6 string array
"Earth" "Jupiter" "Neptune" "Jupiter" "Mars" "Earth"
Convert str to a categorical array.
planets = categorical(str)
planets = 1x6 categorical array
Earth Jupiter Neptune Jupiter Mars Earth
Add missing elements to str and convert it to a categorical array. Where str has missing
values, planets has undefined values.
str(8) = 'Mars'
str = 1x8 string array
Columns 1 through 6
"Earth" "Jupiter" "Neptune" "Jupiter" "Mars" "Earth"
Columns 7 through 8
planets = categorical(str)
planets = 1x8 categorical array
Columns 1 through 6
Earth Jupiter Neptune Jupiter Mars Earth
Create Categorical Arrays