Search code examples
stringmatlabcell

create a cell array of strings matlab


Hi I am trying to create a cell array of strings with:

data = ['1';'2';'3';'4';'5';'6';'7';'8';'9';'10';'11';'12';'13';'14';'15';'16';'17';'18';'19';'20';];

where I expecting a cell array of 25 elements. but I get:

length(data)

= 33

so obviously numbers 12,13 etc are counting as 2 bits.

My question is then how do I ensure the cell array is of length 20? also the function I am putting the cell array into has to be a cell array of strings even though I am using ints!


Solution

  • You need to do:

    data = {'1';'2';'3';'4';'5';'6';'7';'8';'9';'10';'11';'12';'13';'14';'15';'16';'17';'18';'19';'20';};
    

    Use {}. These will form a cell array.