How to convert "cell array" to "character array"

답변 (3개)

Jonas
Jonas 2021년 7월 8일

0 개 추천

the format 'A1' 'B1' 'C1' is not possible with character array, but 'A1B1C1' is possible:
asCell={'A','B','C'}; charArray=[asCell{:}]
Stephen23
Stephen23 2021년 7월 8일
C = {'A1','B1','C1'}
C = 1×3 cell array
{'A1'} {'B1'} {'C1'}
D = vertcat(C{:})
D = 3×2 char array
'A1' 'B1' 'C1'
or
D = char(C)
D = 3×2 char array
'A1' 'B1' 'C1'
DGM
DGM 2021년 7월 8일
편집: DGM 2021년 7월 8일
It's kind of hard to tell what exactly you want, since your example isn't really proper syntax.
If you just have a scalar cell array with a char vector:
A = {'potato'};
B = A{:}
B = 'potato'
If you have a cell array with multiple elements, each containing a char, the answer depends on whether all the char vectors are the same size and what you expect the output to look like.
A = {'potato' 'tomato' 'grapes'};
vertcat(A{:}) % only works if they're all the same size
ans = 3×6 char array
'potato' 'tomato' 'grapes'
horzcat(A{:})
ans = 'potatotomatograpes'

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2021년 7월 8일

편집:

DGM
2021년 7월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by