Matlab: convert array of number to array of strings

34,479

Solution 1

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

s = [12 25 34 466 55]
strtrim(cellstr(num2str(s'))')

Solution 2

Using arrayfun together with num2str would work:

>> A = [12 25 34 466 55]
A =
   12    25    34   466    55

>> arrayfun(@num2str, A, 'UniformOutput', false)
ans = 
    '12'    '25'    '34'    '466'    '55'

Solution 3

Now after MATLAB 2016b, you can simply use

s = [12 25 34 466 55]; 
string(s)
Share:
34,479
olamundo
Author by

olamundo

Updated on May 22, 2020

Comments

  • olamundo
    olamundo almost 4 years

    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.