フィルターのクリア

value replacement in an array

2 ビュー (過去 30 日間)
Yazdan Kordestany
Yazdan Kordestany 2016 年 9 月 9 日
コメント済み: Star Strider 2016 年 9 月 9 日
Hi all,
I have a big 2D array and I want to change some of their values. So, I am using A(A==value)=value2. However, it just works for some specific values, for instance it works, when A(A==7.843120581576564e-04) = 1, but I cannot change it when A(A==0.183079763461368)=2. could the decimal be the reason?
Thanks, Yaz

採用された回答

Star Strider
Star Strider 2016 年 9 月 9 日
My guess is that it’s not an exact match for the value in ‘A’. See Why is 0.3 - 0.2 - 0.1 (or similar) not equal to zero? for an explanation of one possible reason.
  2 件のコメント
Yazdan Kordestany
Yazdan Kordestany 2016 年 9 月 9 日
Thanks Star, I checked and you were right. However, I was not able to solve it yet, so I used excel instead and load it on matlab.
Star Strider
Star Strider 2016 年 9 月 9 日
My pleasure.
If the value already exists in ‘A’ and you want to find other instances of it, use the existing value to compare, since it is likely to have the necessary precision.
Another option is to set a range:
A = 0.183079763461368;
A(A>=0.183079763461367 & A<=0.183079763461369)=2;
This runs without error and sets the single value of ‘A’ here to 2. You will need to experiment with it in your code to see if it does what you want.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by