How to concatenate an array of numbers without for loop
2 ビュー (過去 30 日間)
古いコメントを表示
採用された回答
Stephen23
2018 年 3 月 22 日
>> A = [1,2,3];
>> str = sprintf(', %d',A);
>> str = sprintf('(%s)',str(3:end))
str = (1, 2, 3)
0 件のコメント
その他の回答 (1 件)
Guillaume
2018 年 3 月 22 日
A = [1 2 3];
sprintf('(%s)', strjoin(compose('%d', A), ', '))
3 件のコメント
Guillaume
2018 年 3 月 22 日
compose was introduced in version R2016b. (You should say in your question if you're several versions behind).
In earlier versions, you can replace compose by the undocumented sprintfc:
sprintf('(%s)', strjoin(sprintfc('%d', A), ', '));
Or use Stephen's method of using sprintf then removing the initial ', '.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!