Determining arbitrary precision from text
Mostra commenti meno recenti
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];
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Data Type Conversion in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!