Turn cell array including space (i.e, ' ') into string

조회 수: 4 (최근 30일)
UBADE HAKKI PEKMEZCI
UBADE HAKKI PEKMEZCI 2022년 10월 7일
댓글: UBADE HAKKI PEKMEZCI 2022년 10월 8일
Hello,
I have a cell array including letter chars and also space and i want to turn it into a string.
When I execute the following:
cell_arr = [{'c'} {'a'} {'s'} {'t'} {' '} {'m'} {'e'} {'m'} {'b'} {'e'} {'r'} {'s'}];
strcat(cell_arr{:})
I get following:
ans =
'castmembers'
But I need the following output:
ans =
'cast members'

채택된 답변

Paul
Paul 2022년 10월 7일
cell_arr = [{'c'} {'a'} {'s'} {'t'} {' '} {'m'} {'e'} {'m'} {'b'} {'e'} {'r'} {'s'}];
If a stirng is desired:
join(string(cell_arr),"")
ans = "cast members"
If a char
char(join(string(cell_arr),""))
ans = 'cast members'
  댓글 수: 3
Paul
Paul 2022년 10월 8일
Please show the exact code that yielded the above result.
As shown here, the result should not have a trailing space, at least in 2022b.
cell_arr = [{'c'} {'a'} {'s'} {'t'} {' '} {'m'} {'e'} {'m'} {'b'} {'e'} {'r'} {'s'}];
join(string(cell_arr),"")
ans = "cast members"
UBADE HAKKI PEKMEZCI
UBADE HAKKI PEKMEZCI 2022년 10월 8일
I tried it on my phone last time, but when I try on PC it works properly. Thanks a lot.

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

추가 답변 (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