how to read and change entries in a large array

1 回表示 (過去 30 日間)
Daniel Hamilton
Daniel Hamilton 2018 年 2 月 26 日
コメント済み: KL 2018 年 2 月 26 日
I have a 842x650, i want to read through every entry, check its value and if its under a certain value change it to zero. Any help would be amazing !!

採用された回答

KL
KL 2018 年 2 月 26 日
It's easier to answer with an example. Let's say we have a matrix of 5x5 with random numbers and you want to find the elements that are between 0.5 and 0.75 and then make it to zero.
A = rand(5,5)
ind = A>=0.5 & A<=0.75;
A(ind) = 0;
A
and now an example result is (before and after),
A =
0.8001 0.1455 0.1450 0.4018 0.2400
0.4314 0.1361 0.8530 0.0760 0.4173
0.9106 0.8693 0.6221 0.2399 0.0497
0.1818 0.5797 0.3510 0.1233 0.9027
0.2638 0.5499 0.5132 0.1839 0.9448
A =
0.8001 0.1455 0.1450 0.4018 0.2400
0.4314 0.1361 0.8530 0.0760 0.4173
0.9106 0.8693 0 0.2399 0.0497
0.1818 0 0.3510 0.1233 0.9027
0.2638 0 0 0.1839 0.9448
  1 件のコメント
KL
KL 2018 年 2 月 26 日
I'd also recommend reading a bit about floating point numbers. Various threads with extensive explanations exist, probably start with this one: https://www.mathworks.com/matlabcentral/answers/57444-faq-why-is-0-3-0-2-0-1-not-equal-to-zero

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

その他の回答 (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