How to get more precision in comparing Elements of Matrix

3 ビュー (過去 30 日間)
Ahmed khliaa
Ahmed khliaa 2017 年 11 月 21 日
編集済み: Adam 2017 年 11 月 21 日
I have a double matrix and i want to pick up the largest element in each column . I found out that Matlab compares only ith 4 numbers after the point , that's what actually matlab shows in the variables window. By changing the Format in the comand windows i get this :
format long
ans =
0.001016470327852
ans =
0.001024700640374
But Matlab is only comparing 0.0010 and considering them equal ...
Thank you in advance
  1 件のコメント
Adam
Adam 2017 年 11 月 21 日
編集済み: Adam 2017 年 11 月 21 日
Matlab uses the complete number for maths. How it is formatted for visualisation is irrelevant. If you need the difference to a high number of decimal places then that is different, but up to double precision the maths is precise for comparing equality or greater than operations.
>> a = 0.001016470327852
a =
0.001016470327852
>> b = 0.001024700640374
b =
0.001024700640374
>> a == b
ans =
logical
0
>> b > a
ans =
logical
1

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by