-1

So ,

i have a cell array(1x5 cell) like this:

{[1111] [1111] [1010] [1000] [1011]}

the elements inside the cell array are type of double , but i want them to be type of char like this :

{'1111' '1111' '1010' '1000' '1011'}

i tried to convert them with num2str but i get the error Undefined function 'abs' for input arguments of type 'cell'. , basically meaning that i cannot use the function num2str for cell arrays

Anyone has an idea how to convert double to char in cell arrays?

1 Answers1

2

You can loop over all the cells.

input = {1111, 1111, 1010, 1000, 1011};
output = cellfun(@num2str, input, 'un', 0);
>> output
output =
  1×5 cell array
    {'1111'}    {'1111'}    {'1010'}    {'1000'}    {'1011'}

Alternatively there is this string class available since R2016b which may be relevant to use for your case:

outstr = string(input);
>> outstr
outstr = 
  1×5 string array
    "1111"    "1111"    "1010"    "1000"    "1011"

However if you strictly want a cell array with characters in each cell, you can further use cellstr:

output = cellstr(outstr);
Sardar Usama
  • 19,536
  • 9
  • 36
  • 58