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
Determining arbitrary precision from text
1 次查看(过去 30 天)
显示 更早的评论
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];
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!