vector conversion from a vector of numbers to a vector cell of chars.
Mostrar comentarios más antiguos
Hello,
In MATLAB I have this vector: Y=[0 4 6] and I need to convert it to this format X={'0' '4' '6'}.
Not sure how to do it.
Thank you
6 comentarios
@Pierre Not sure if this is what you want
Y=[0 4 6]
X = {string(Y)}
Walter Roberson
el 3 de Feb. de 2025
There is a real difference between {["0" "4" "6"]} and {'0' '4' '6'} ... and a difference again for {"0" "4" "6"}.
In the case of {["0" "4" "6"]} you get out a 1 x 1 cell that contains a 1 x 3 string array. In the case of {'0' '4' '6'} you get out a 1 x 3 cell each entry of which is 1 x 1 char vector.
cell arrays containing strings are not recognized as being in "cellstr" format.
Stephen23
el 3 de Feb. de 2025
"cell arrays containing strings are..."
for good reasons discouraged by the documentation:
which states: "When you have multiple strings, store them in a string array, not a cell array... String arrays are more efficient than cell arrays for storing and manipulating text.... Avoid using cell arrays of strings. When you use cell arrays, you give up the performance advantages that come from using string arrays. And in fact, most functions do not accept cell arrays of strings as input arguments, options, or values of name-value pairs."
Pierre
el 3 de Feb. de 2025
Walter Roberson
el 3 de Feb. de 2025
Use any of the techniques indicated by @Stephen23
Pierre
el 5 de Feb. de 2025
Respuesta aceptada
Más respuestas (1)
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!