How to Concatenate two large numbers in Matlab

Hello everyone, This could come as a very basic question. I'm trying to concate 2 large numbers. For example: 5602007248 and 5602007720. The answer should be 56020072485602007720.
Currently, i'm trying converting to str and using strcat then converting back to num, but that doesnt seem to work somehow.
Help really appreciated. Thanks Raj

 채택된 답변

Matt J
Matt J 2012년 11월 26일
편집: Matt J 2012년 11월 26일

0 개 추천

str2num(sprintf('%d%d',5602007248,5602007720))

추가 답변 (2개)

Muruganandham Subramanian
Muruganandham Subramanian 2012년 11월 26일

0 개 추천

a=10; b=20;
a1=num2str(a);
b1=num2str(b);
c=strcat(a1,b1)

댓글 수: 4

Rajesh
Rajesh 2012년 11월 26일
Hello Muruganadham, This solution works for small numbers as you mentioned in your answer, the problem is that when i use num2str(5602007720) and num2str(5602007720)... in both cases the answer comes as 5.60201e+009... which is not correct... and the appending these 2 numbers are not the actual concat of the original numbers...
Rajesh
Rajesh 2012년 11월 26일
sorry the example numbers are 5602007248 and 5602007720... typo in my cooment above...
It's working fing fine.. If you stil have a doubt you can compare by ur expected and caluculated by 'strcmp'.I have tried that too..
Rajesh
Rajesh 2012년 11월 26일
The problem is that when i use num2str for a large number, it rounds the number and the final result wasnt the same, but the solution by Matt works great for large numbers.
Thanks for the response Muruganandham.

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

Matt J
Matt J 2012년 11월 26일

0 개 추천

n=floor(log10(5602007720));
10^(n+1)*5602007248 + 5602007720

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

질문:

2012년 11월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by