How to concatenate an array of numbers without for loop

4 views (last 30 days)
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.

Accepted Answer

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

More Answers (1)

Guillaume
Guillaume on 22 Mar 2018
A = [1 2 3];
sprintf('(%s)', strjoin(compose('%d', A), ', '))
  3 Comments

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!

Translated by