vector conversion from a vector of numbers to a vector cell of chars.
Mostra commenti meno recenti
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 Commenti
@Pierre Not sure if this is what you want
Y=[0 4 6]
X = {string(Y)}
Walter Roberson
il 3 Feb 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
il 3 Feb 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
il 3 Feb 2025
Walter Roberson
il 3 Feb 2025
Use any of the techniques indicated by @Stephen23
Pierre
il 5 Feb 2025
Risposta accettata
Più risposte (1)
Categorie
Scopri di più su Data Type Conversion in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!