Programming and Data Types | ![]() ![]() |
Converting to a Cell Array of Strings
The cellstr
function converts a character array into a cell array of strings. Consider the character array
data = ['Allison Jones';'Development ';'Phoenix '];
Each row of the matrix is padded so that all have equal length (in this case, 13 characters).
Now use cellstr
to create a column vector of cells, each cell containing one of the strings from the data
array.
celldata = cellstr(data) celldata = 'Allison Jones' 'Development' 'Phoenix'
Note that the cellstr
function strips off the blanks that pad the rows of the input string matrix.
length(celldata{3}) ans = 7
The iscellstr
function determines if the input argument is a cell array of strings. It returns a logical true (1) in the case of celldata
.
iscellstr(celldata) ans = 1
Use char
to convert back to a standard padded character array.
strings = char(celldata) strings = Allison Jones Development Phoenix
The str2double
function converts a cell array of strings to the double-precision values represented by the strings.
c = {'37.294e-1'; '-58.375'; '13.796'}; str2double(c) ans = 3.7294 -58.3750 13.7960
![]() | Cell Arrays of Strings | String Comparisons | ![]() |