To find four-digit numbers after comma
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hamza YAPICI
il 29 Gen 2020
Commentato: Walter Roberson
il 29 Gen 2020
Hello,
I am trying to find first 1,2,3,4 digit numbers after the comma in the matrix below. The numbers with more than 4 digit have to be eliminated. How can I find this numbers?
a = [0.0001255 0.0212215 0.20222022 0.9805446;
0.0222 0.2026454 0.0100 0.98052516;
0.0010 0.002 0.1 0.2000;
0.23156498 0.6545648 0.467823 0.9876564];
However, all numbers must be in the same row. For example, a (2, :) should not be selected.
2 Commenti
Risposta accettata
Walter Roberson
il 29 Gen 2020
sprintf('%.99g', 0.0222)
ans =
'0.0222000000000000009825473767932635382749140262603759765625'
*None* of the entries in your matrix are 4 digits after the decimal. MATLAB does not store floating point numbers in decimal, and there is no exact finite binary floating point representation of 0.1. The *only* binary floating point values that are four digits after the decimal point are
0.0625 0.1875 0.3125 0.4375 0.5625 0.6875 0.8125 0.9375
2 Commenti
Walter Roberson
il 29 Gen 2020
I did already help you. The answer given that matrix is to return empty because you do not have even one 4 digit number in your input.
This is important! MATLAB does not handle fractions in decimal! Very few programming languages handle fractions in decimal. The only existing commercial implementation of decimal floating point hardware that I know of is the IBM Z9 series.
The values of the 3rd row of the matrix are
0.001000000000000000020816681711721685132943093776702880859375
0.00200000000000000004163336342344337026588618755340576171875
0.1000000000000000055511151231257827021181583404541015625
0.200000000000000011102230246251565404236316680908203125
These are not even remotely close to being 4 digit numbers! More like 60 digit numbers.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!