How to Concatenate two large numbers in Matlab

5 ビュー (過去 30 日間)
Rajesh
Rajesh 2012 年 11 月 26 日
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 日
str2num(sprintf('%d%d',5602007248,5602007720))
  1 件のコメント
Rajesh
Rajesh 2012 年 11 月 26 日
Thanks for the help Matt

サインインしてコメントする。

その他の回答 (2 件)

Muruganandham Subramanian
Muruganandham Subramanian 2012 年 11 月 26 日
a=10; b=20;
a1=num2str(a);
b1=num2str(b);
c=strcat(a1,b1)
  4 件のコメント
Muruganandham Subramanian
Muruganandham Subramanian 2012 年 11 月 26 日
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 日
n=floor(log10(5602007720));
10^(n+1)*5602007248 + 5602007720
  1 件のコメント
Rajesh
Rajesh 2012 年 11 月 26 日
Thanks Matt... this one works great too...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by