"char" doesn't always maintain orientation of input array
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
The "char" function maintains orientation of input arrays except for categorical arrays:
>> categorical(["A" "B"])
ans = 1×2 categorical array
A B
>> char(categorical(["A" "B"]))
ans = 2×1 char array
'A'
'B'
Does anyone know the rationale behind this?
0 comentarios
Respuestas (1)
Voss
el 8 de Nov. de 2022
I imagine the rationale is that, in case the elements of the categorical array are multiple characters long, e.g.:
categorical(["Abbot" "Beto"])
You want to be able to know where one ends and the next one begins, so you put them on different rows:
char(categorical(["Abbot" "Beto"]))
as opposed to having the result be:
'AbbotBeto'
which can be ambiguous:
categorical(["0" "1" "10" "11"])
char(categorical(["0" "1" "10" "11"]))
since in this case '011011' could be interpreted as '0', '1', '10', '11', or as '0', '11', '0', '11', for example.
Just a guess.
1 comentario
Ver también
Categorías
Más información sobre Categorical Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!