cell array to string array

Hi
I have a cell array consisting of strings. I would like to convert it to an array with one word in each cell.
for example, the cell array: "Hello B
Hi A
Where is D?
and I need: Hello
B
Hi etc.
TIA

 采纳的回答

Something like this
A = {'Hello B Hi A Where is D?'};
B = strsplit(A{:}, ' ')';
Result:
B =
7×1 cell array
{'Hello'}
{'B' }
{'Hi' }
{'A' }
{'Where'}
{'is' }
{'D?' }

6 个评论

Not a exactly.. A is 1x1 cell and my input is 3x1 cell, and i need the input to be a string array of words...
Can you give an example of your input?
my input is:
{Hello B}
{Hi A}
{D}
its a 3x1 cell.
Thanks for the patience.
Try this
A = {'Hello B', ...
'Hi A', ...
'D'};
B = strsplit(strjoin(A, ' '), ' ')';
Amazing! thank you so much!
Glad to be of help.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by