How can I turn a 1*1 cell into a cell array?

For example, what is the easiest way to turn a 1*1 cell 'a b c d e' into a cell array {'a'} {'b'} {'c'} {'d'} {'e'}? Please! Anyone can help me?

 Akzeptierte Antwort

Sameer
Sameer am 19 Aug. 2024
Bearbeitet: Sameer am 19 Aug. 2024

1 Stimme

Hi
To split a 1x1 cell containing a string and convert the result into a cell array, you can utilize the "strsplit" function.
originalCell = {'a b c d e'};
splitArray = strsplit(originalCell{1});
disp(splitArray);
Hope this helps!

3 Kommentare

marvellous
marvellous am 20 Aug. 2024
Thanks! It really helps!
Another way:
originalCell = {'a b c d e'};
regexp(originalCell{1}, ' +', 'split')
ans = 1x5 cell array
{'a'} {'b'} {'c'} {'d'} {'e'}
marvellous
marvellous am 21 Aug. 2024
Oh, I didn't expect it, thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2023a

Gefragt:

am 19 Aug. 2024

Kommentiert:

am 21 Aug. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by