フィルターのクリア

Determining arbitrary precision from text

1 回表示 (過去 30 日間)
Edward
Edward 2012 年 1 月 20 日
I am reading a number with arbitray precision, but I need to parse this into a string using a particular format.
Example 1: 1.015
Example 2: 60.15
Example 3: 700.150
In the first example, the correct string is CASE1_15. In the second example, the correct string is CASE60_15. In the last example, the correct string is CASE700_150
The code below accomplishes this, where the number has been stored in the fullcase column of matrix a, assuming a precision of 3 decimal places. Unfortunately, this requires me to know the precision beforehand. This means the code works for Examples 1 and 3, but fails for Example 2. If I alter code(replacing 1000 with 100), it fails for Examples 1 and 3, but works for Example 2. Isn't there some elegant means to detect the precision stored in that column so the code works no matter what the precision is?
strCase = num2str(floor(a(j,fullcase)));
strSubcase = num2str((a(j,fullcase)-floor(a(j,fullcase)))*1000);
fullCase = ['CASE',strCase,'_',strSubcase];

採用された回答

Walter Roberson
Walter Roberson 2012 年 1 月 20 日
Once you have converted to numeric form, you cannot determine the precision -- and the number actually stored probably isn't what you are expecting. Please see http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by