Use element values for IF statements

3 ビュー (過去 30 日間)
olu
olu 2014 年 4 月 19 日
編集済み: dpb 2014 年 4 月 20 日
Hi all,
I would like to use the value of the elements in matrix B as condition for changing the values in matrix A. Note that Both A & B have the same size. For example, let A = [1 1;1 1] and B = [120 50; 75 175]. If the values of any element in B is greater than 100, I would like to change the values of the element in its corresponding position in A to zero(0). So the new matrix A for this example would be A = [0 1; 1 0]. Please how can I code this? Thanks in advance.
OlFat

採用された回答

Image Analyst
Image Analyst 2014 年 4 月 19 日
A = double(B <= 100)
  1 件のコメント
olu
olu 2014 年 4 月 19 日
Thanks mate

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

その他の回答 (2 件)

dpb
dpb 2014 年 4 月 19 日
編集済み: dpb 2014 年 4 月 20 日
A basic use of "logical addressing"...
ix=B>100; % the logical condition vector A(ix); % the substitution
You can, of course, combine the two and eliminate the intermediary--
A(B>100)=0;
  1 件のコメント
olu
olu 2014 年 4 月 19 日
Thanks dpb

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


Matt J
Matt J 2014 年 4 月 19 日
  1 件のコメント
olu
olu 2014 年 4 月 19 日
Thanks Matt.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by