Watt Cnx
Watt Cnx

Reputation: 49

Finding index of specific values in matrix

In example matrix

a1=[1;1;1;2;2];
b1=[1;1;2;2;2];

Can I compare a1 and b1 matrix, which is equal in the case of 1 value in a1 matrix?

target matrix

c1=[1,1,0,0,0];

Upvotes: 1

Views: 37

Answers (2)

Suever
Suever

Reputation: 65430

You can create a logical array by using the == operator. Based on your question, I assume you want where a1 and b1 are both equal to 1. We can use the and (&) operator to combine the two logical arrays created by a1 == 1 and b1 == 1.

c1 = a1 == 1 & b1 == 1;
%   1   1   0   0   0

Upvotes: 1

rahnema1
rahnema1

Reputation: 15837

You can use and operator &

a1 == 1 & b1 == 1

Upvotes: 1

Related Questions