Reputation: 18859
I have a string array:
array = ['123';'abc';'uvw'];
I want convert it to a cell array of string:
cellArr = {'123';'abc';'uvw'};
There are two ways in my idea: allocating a cell array then using a for loop or
cellArr = arrayfun(@(x) array(x,:),1:size(array,1),'UniformOutput',false)';
But I'm not sure if there is a build-in function do this more effective.
Upvotes: 1
Views: 7191
Reputation: 13081
Use cellstr()
. Simply cellstr (array)
should work. It also works in Octave.
Alternatively, a more complicated but fun way to look into is
mat2cell (array, ones (size (array, 1), 1), size (array, 2))
which in Octave can be
mat2cell (array, ones (rows (array), 1), columns (array))
Upvotes: 2