Convert cell array to array of strings

조회 수: 9 (최근 30일)
JFz
JFz 2017년 3월 3일
댓글: Adam 2017년 3월 3일
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.

답변 (1개)

Adam
Adam 2017년 3월 3일
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
JFz
JFz 2017년 3월 3일
Thanks. But I got this error at s = string(a); Undefined function 'string' for input arguments of type 'cell'.
Adam
Adam 2017년 3월 3일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by