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

4 visualizaciones (últimos 30 días)
marvellous
marvellous el 19 de Ag. de 2024
Comentada: marvellous el 21 de Ag. de 2024
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?

Respuesta aceptada

Sameer
Sameer el 19 de Ag. de 2024
Editada: Sameer el 19 de Ag. de 2024
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 comentarios
Walter Roberson
Walter Roberson el 20 de Ag. de 2024
Another way:
originalCell = {'a b c d e'};
regexp(originalCell{1}, ' +', 'split')
ans = 1x5 cell array
{'a'} {'b'} {'c'} {'d'} {'e'}
marvellous
marvellous el 21 de Ag. de 2024
Oh, I didn't expect it, thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by