フィルターのクリア

Why isn't this value being saved using ismember and round?

1 回表示 (過去 30 日間)
Wolfgang McCormack
Wolfgang McCormack 2021 年 3 月 13 日
回答済み: Star Strider 2021 年 3 月 13 日
Hi all,
I have the following code and it almost works for all my values except two. Nothing being saved in Xsaved
AllRatios = ([0.1:0.05:1])
%it does not work for the following ratios: 0.45 and 0.65. I wonder if
%that's because thry are less than 0.45 and are rounded or not!
Actualvalue = 0.448533333333333
CurRatio= round(Actualvalue,2) % it returns 45, I tried it with 'significant' method as well
for i = 62:62
if ismember(CurRatio,AllRatios)
Xsaved(1,i) = ([CurRatio])
else
NoSaved = 0
end
end

採用された回答

Star Strider
Star Strider 2021 年 3 月 13 日
Since decimal fractions are never exact (even using round), use ismembertol (introduced in R2015a) for the comparisons. It will be necesary to experiment with the tolerance value to get it to work as desired.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by