Convert a string array to a cell array of strings

조회 수: 2 (최근 30일)
Matt J
Matt J 2020년 9월 14일
댓글: Walter Roberson 2020년 9월 14일
Starting with a cell array of strings,
>> C={'person','woman','man','camera','TV'};
I know that it is possible to convert to a string array,
>> S = string(C)
S =
1×5 string array
"person" "woman" "man" "camera" "TV"
I am wondering, however, whether there is a command to do the reverse conversion. I can make my own as follows,
>> C=arrayfun(@(s)char(s),S,'uni',0)
C =
1×5 cell array
{'person'} {'woman'} {'man'} {'camera'} {'TV'}
However, I am wondering if there is a native Matlab command for doing this that I have overlooked.

채택된 답변

Walter Roberson
Walter Roberson 2020년 9월 14일
  댓글 수: 2
Matt J
Matt J 2020년 9월 14일
Ah, good. Counter-intuitively named though, IMO.
Walter Roberson
Walter Roberson 2020년 9월 14일
It could be claimed that it is natural because it takes string ('str') and produces a cell ('cell')
... But I wouldn't claim that.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by