How to concatenate an array of numbers without for loop
4 次查看(过去 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!