How to append several elements to a single element in an array?

7 次查看(过去 30 天)
I have an array like:
A = [1 2 3 4 5 6 7 8 9 10];
I want to merge all the elements into a single element, like:
A = [12345678910];
but I cannot see any clear way to do so, as functions like 'reshape' or 'horizcat' simple place all the elements vertically, instead of appending all the values into one long element.
Any help would be really appreciated!
Thanks.

采纳的回答

Birdman
Birdman 2018-1-31
编辑:Birdman 2018-1-31
%%to see the complete number with all digits
format longg
str2double(strjoin(string(A),''))
  6 个评论

请先登录,再进行评论。

更多回答(1 个)

Stephen23
Stephen23 2018-1-31
编辑:Stephen23 2018-1-31
Much faster and simpler than using string, strjoin, and str2double:
>> A = [1 2 3 4 5 6 7 8 9 10];
>> N = sscanf(sprintf('%d',A),'%f')
N = 12345678910

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by