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

 Réponse acceptée

Ameer Hamza
Ameer Hamza le 2 Avr 2020
Modifié(e) : Ameer Hamza le 2 Avr 2020

0 votes

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 commentaires

Ido Gross
Ido Gross le 2 Avr 2020
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 le 2 Avr 2020
Modifié(e) : Ameer Hamza le 2 Avr 2020
Can you give an example of your input?
Ido Gross
Ido Gross le 2 Avr 2020
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 le 2 Avr 2020
Amazing! thank you so much!
Ameer Hamza
Ameer Hamza le 2 Avr 2020
Glad to be of help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by