To find four-digit numbers after comma

8 次查看(过去 30 天)
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 个评论
Hamza YAPICI
Hamza YAPICI 2020-1-29
编辑:Hamza YAPICI 2020-1-29
in my homework:
The answer should be;
b = [0.0010 0.0020 0.1000 0.2000]

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-1-29
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 个评论
Hamza YAPICI
Hamza YAPICI 2020-1-29
Dear sir,
In my homework, I need to find a(3, :). Please, could you help me about this issue?
Walter Roberson
Walter Roberson 2020-1-29
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by