Convert cell array to array of strings

18 vues (au cours des 30 derniers jours)
JFz
JFz le 3 Mar 2017
Commenté : Adam le 3 Mar 2017
Hi,
I have a cell array a of 10000x1 cell. Each cell contains a string. I would like to strsplit the string in each cell but I keep getting this error;
C = strsplit({a}, '_'); Error using strsplit (line 76) First input must be a char row vector.
What is the problem here?
thanks for any help.

Réponses (1)

Adam
Adam le 3 Mar 2017
s = string( a );
C = arrayfun( @(x) strsplit( x, '_' ), s, 'UniformOutput', false );
should work, or you could just use cellfun on the cell array itself. Depends if having a string array is useful for any other purpose. I don't know which is faster if that matters.
  2 commentaires
JFz
JFz le 3 Mar 2017
Thanks. But I got this error at s = string(a); Undefined function 'string' for input arguments of type 'cell'.
Adam
Adam le 3 Mar 2017
I guess in that case you are using an older version of Matlab that doesn't yet have strings
C = cellfun( @(x) strsplit( x, '_' ), a, 'UniformOutput', false );
should work

Connectez-vous pour commenter.

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by