1

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.

0

1 Answer 1

2

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))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.