Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab: convert array of number to array of strings

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.

like image 772
olamundo Avatar asked Aug 28 '12 17:08

olamundo


People also ask

How do I convert an array of numbers to strings?

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.

Can you have an array of strings in MATLAB?

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.

How do you convert an array to a number in MATLAB?

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.

How do I concatenate a number to a string in MATLAB?

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).


1 Answers

An array of strings has to be a cell array. That said:

s = [12 25 34 466 55] strtrim(cellstr(num2str(s'))') 
like image 148
Peter Avatar answered Sep 19 '22 12:09

Peter