Create an array of matlab row cells

Hi, I am trying to create an array of row cells with:
data = ['1';'2';'3';'4';'5';'6';'7';'8';'9';'10';'11';'12';'13';'14';'15';'16';'17';'18';'19';'20';]; 

where I expect an array of cells of 25 elements. but I get:

 length(data) = 33 

therefore, the numbers 12, 13, etc. are considered 2 bits.

My question is, how can I guarantee that an array of cells has a length of 20? also the function that i put in the array of cells should be an array of row cells even if i use ints!

+7
string matlab cell
source share
2 answers

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 {} . They form an array of cells.

+16
source share

You can use {} instead of [] to create a cell, or you can use strsplit to create an arbitrary cell of row lengths representing numbers from 1 to N :

 data = strsplit(num2str(1:N)); 

Update: The fastest way to do this now is with the undocumented sprintfc function (note the "c" at the end), which prints each element in its own cell:

 >> A = sprintfc('%g',1:20) A = Columns 1 through 11 '1' '2' '3' '4' '5' '6' '7' '8' '9' '10' '11' Columns 12 through 20 '12' '13' '14' '15' '16' '17' '18' '19' '20' >> which sprintfc built-in (undocumented) 
+11
source share

All Articles