sscanf is truncating my floating point number

Hi
I am trying to use sscanf to extract data from a string, but it is truncating my floating point number. The code I am using is:
sscanf(tempstr, '%f V,%d counts,%d ms')
The data is like this: 0.2981427192 V,34 counts,500 ms
I get: ans =
0.2981
34.0000
500.0000
I want all the floating point digits. I have tried to specify a length (%12f), and numerous other things, none of which have worked. Any help would be appreciated.
Thanks Rebecca

1 件のコメント

Stephen23
Stephen23 2016 年 5 月 6 日
編集済み: Stephen23 2016 年 5 月 6 日
@Rebecca Prescott: Don't worry, MATLAB has not eaten your digits! Actually sscanf is working fine: it is just how the values are displayed. See format for more info on different display options.

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

 採用された回答

Star Strider
Star Strider 2016 年 5 月 6 日

2 投票

Type:
format long g
in your script or Command Window before your sscanf call. All the digits should be visible.

3 件のコメント

Rebecca Prescott
Rebecca Prescott 2016 年 5 月 6 日
Thank you so much, that worked.
Star Strider
Star Strider 2016 年 5 月 6 日
My pleasure.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLanguage Support についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by