Clear Filters
Clear Filters

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

60 views (last 30 days)
marvellous
marvellous on 19 Aug 2024 at 12:05
Commented: marvellous on 21 Aug 2024 at 2:24
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?

Accepted Answer

Sameer
Sameer on 19 Aug 2024 at 12:16
Edited: Sameer on 19 Aug 2024 at 12:26
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 Comments
Walter Roberson
Walter Roberson on 20 Aug 2024 at 19:32
Another way:
originalCell = {'a b c d e'};
regexp(originalCell{1}, ' +', 'split')
ans = 1x5 cell array
{'a'} {'b'} {'c'} {'d'} {'e'}
marvellous
marvellous on 21 Aug 2024 at 2:24
Oh, I didn't expect it, thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!