How can I convert [12 25 34 466 55]
to an array of strings ['12' '25' '34' '466' '55']
? The conversion functions I know convert that array to one string representing the entire array.
To convert an array of numbers to an array of strings, call the map() method on the array, and on each iteration, convert the number to a string. The map method will return a new array containing only strings.
MATLAB® provides string arrays to store pieces of text. Each element of a string array contains a 1-by-n sequence of characters. You can create a string using double quotes. As an alternative, you can convert a character vector to a string using the string function.
X = str2num( txt ) converts a character array or string scalar to a numeric matrix. The input can include spaces, commas, and semicolons to indicate separate elements. If str2num cannot parse the input as numeric values, then it returns an empty matrix.
You can concatenate strings using strcat . If you plan on concatenating numbers as strings, you must first use num2str to convert the numbers to strings. Also, strings can't be stored in a vector or matrix, so f must be defined as a cell array, and must be indexed using { and } (instead of normal round brackets).
An array of strings has to be a cell array. That said:
s = [12 25 34 466 55] strtrim(cellstr(num2str(s'))')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With