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

조회 수: 5 (최근 30일)
Patrick Ellison
Patrick Ellison 2018년 1월 31일
편집: Birdman 2018년 1월 31일
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.
  댓글 수: 1
Stephen23
Stephen23 2018년 1월 31일
Note to others: see my answer if you want a simpler, faster solution.

댓글을 달려면 로그인하십시오.

채택된 답변

Birdman
Birdman 2018년 1월 31일
편집: Birdman 2018년 1월 31일
%%to see the complete number with all digits
format longg
str2double(strjoin(string(A),''))
  댓글 수: 6
Birdman
Birdman 2018년 1월 31일
You are welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (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