convert string to cell array in matlab

To convert a string to a cell array, you can simply use the cellstr function as follows:

main.m
str = 'string';
cell_array = cellstr(str);
43 chars
3 lines

This will convert the string 'string' to a cell array {'string'}. If the input string contains multiple words separated by spaces, each word will be stored in a separate cell:

main.m
str = 'this is a string';
cell_array = cellstr(str);
53 chars
3 lines

This will result in the cell array {'this', 'is', 'a', 'string'}.

related categories

gistlibby LogSnag