how to replace values of a matrix, if another matrix meet certain conditions?

2 ビュー (過去 30 日間)
Alecd
Alecd 2017 年 4 月 4 日
コメント済み: Joseph Cheng 2017 年 4 月 4 日
Hello
so I have a matrix A=[20 17 18 24, 12 22 27 11, 30 10 15 23, 28 20 14 11]
and a matrix B filled with zeros, of the same size (4x4).
I want to say that if the values of A are bigger than 18, then change the values in matrix B. Also taking into account the position of the elements, so for example the first element A(1,1) is bigger than 18, then B(1,1) will change to 1.
Edit: What if I have 3 matrixes, and the matrix B. So I want to say that if the values in matrix A are bigger than 18, and the values in matrix C are bigger than 10 and the values in matrix D are bigger than 30, then in Matrix B, change from 0 to 1, the element that meet the three conditions.

回答 (1 件)

Joseph Cheng
Joseph Cheng 2017 年 4 月 4 日
編集済み: Joseph Cheng 2017 年 4 月 4 日
i may be over simplifying it but doesn't the greater than (>) inequality just do it?
A=magic(5)
B=A>18
  3 件のコメント
Joseph Cheng
Joseph Cheng 2017 年 4 月 4 日
at this point my point stands and you should look up how to use logical operands https://www.mathworks.com/help/matlab/logical-operations.html if you are familiar with what the terms AND, OR, XOR, NOR, etc mean
Joseph Cheng
Joseph Cheng 2017 年 4 月 4 日
such that
magic(5)>10 & magic(5)<20
so the first part is highlighting with 1's which are greater than 10, second half which are less than 20. then the & is saying which positions are both 1s.

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

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by