How to concatenate an array of numbers without for loop

2 ビュー (過去 30 日間)
JFz
JFz 2018 年 3 月 22 日
コメント済み: JFz 2018 年 3 月 22 日
Hi, I have an array of integer numbers A = [1, 2, 3]. I would like to concatenate the numbers for use in SQL statement like '(1, 2, 3)'. How to do that without a for loop? Thanks.

採用された回答

Stephen23
Stephen23 2018 年 3 月 22 日
>> A = [1,2,3];
>> str = sprintf(', %d',A);
>> str = sprintf('(%s)',str(3:end))
str = (1, 2, 3)

その他の回答 (1 件)

Guillaume
Guillaume 2018 年 3 月 22 日
A = [1 2 3];
sprintf('(%s)', strjoin(compose('%d', A), ', '))
  3 件のコメント
JFz
JFz 2018 年 3 月 22 日
Thanks!

サインインしてコメントする。

カテゴリ

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