Turn cell array including space (i.e, ' ') into string
4 次查看(过去 30 天)
显示 更早的评论
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'
0 个评论
采纳的回答
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),"")
If a char
char(join(string(cell_arr),""))
3 个评论
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),"")
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!