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

4 ビュー (過去 30 日間)
UBADE HAKKI PEKMEZCI
UBADE HAKKI PEKMEZCI 2022 年 10 月 7 日
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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by