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

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 2일
편집: Ameer Hamza 2020년 4월 2일

0 개 추천

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

Ido Gross
Ido Gross 2020년 4월 2일
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...
Ameer Hamza
Ameer Hamza 2020년 4월 2일
편집: Ameer Hamza 2020년 4월 2일
Can you give an example of your input?
Ido Gross
Ido Gross 2020년 4월 2일
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, ' '), ' ')';
Ido Gross
Ido Gross 2020년 4월 2일
Amazing! thank you so much!
Ameer Hamza
Ameer Hamza 2020년 4월 2일
Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2020년 4월 2일

댓글:

2023년 7월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by