To find four-digit numbers after comma

19 views (last 30 days)
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.
Hamza YAPICI on 29 Jan 2020
Edited: Hamza YAPICI on 29 Jan 2020
in my homework:
The answer should be;
b = [0.0010 0.0020 0.1000 0.2000]

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Jan 2020
sprintf('%.99g', 0.0222)
ans =
*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
Walter Roberson
Walter Roberson on 29 Jan 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
These are not even remotely close to being 4 digit numbers! More like 60 digit numbers.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!