Hi, I want to convert a string into a number however I don't want to use str2num since I loose extra digits (see example below). Can I use some other MATLAB function?
data = 0.0782238;
s = str2num(data); %Don't want this since s = 0.0782 and I'm loosing three extra digits

4 件のコメント

Patrik Ek
Patrik Ek 2014 年 2 月 5 日
Are you sure? It could just be matlabs display. Try
format long
Lily
Lily 2014 年 2 月 5 日
ok, so MATLAB will store the value but shortens the display? ;)
Patrik Ek
Patrik Ek 2014 年 2 月 5 日
Exactly. You could try
a=1.1111111;
a
b=2.2222222;
format long;
a+b
Lily
Lily 2014 年 2 月 6 日
nice, thx :)

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

 採用された回答

Walter Roberson
Walter Roberson 2014 年 2 月 5 日

1 投票

str2num() does not lose those extra digits. Instead, you are not displaying the full width of the number. At the MATLAB command line give the command
format long g
and try your code again.

その他の回答 (1 件)

Wayne King
Wayne King 2014 年 2 月 5 日
編集済み: Wayne King 2014 年 2 月 5 日

0 投票

how about just using format long
data = '0.0782238';
data = str2num(data);
format long
data

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

質問済み:

2014 年 2 月 5 日

コメント済み:

2014 年 2 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by