MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何在MATLAB中将单元格中的字符串连接在一起并在它们之间留有空格? (https://www.labfans.com/bbs/showthread.php?t=26588)

poster 2019-12-14 20:13

如何在MATLAB中将单元格中的字符串连接在一起并在它们之间留有空格?
 
我想连接(用空格填充)单元格数组{'a', 'b'}中的字符串以给出单个字符串'a b' 。如何在MATLAB中执行此操作?



[B]回答:[/B]

您可以通过使用单元格数组作为sprintf函数的一组参数来作弊,然后使用strtrim清除多余的空格:

strs = {'a', 'b', 'c'}; strs_spaces = sprintf('%s ' ,strs{:}); trimmed = strtrim(strs_spaces); 脏,但我喜欢...



[url=https://stackoverflow.com/questions/5292437]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 09:13

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.