user5340565
user5340565

Reputation:

In Matlab, how can I find the rows where two arrays are equal?

For example, I'm looking at the first column in two arrays, and I created a logical array that finds all the values greater than 5 in both arrays.

Now, how can I find all the rows where the values in the matrices are greater than 5? In other words, the rows where there are 1's in the two logical arrays. For example: coupling = row1 == row2; This is just giving me a syntax error.

Upvotes: 0

Views: 179

Answers (1)

Your code

coupling = row1 == row2;

should not give a syntax error: it should give you a logical array in coupling unless the dimensions of row1 and row2 are different.

If your logical array row1 and your logical array row2 have the same size, then you can perform a logical AND on them by calling

coupling = row1 & row2;

which will be a logical array of the same size, having values of 1 precisely at the positions where row1 and row1 both have a value of 1.

Upvotes: 1

Related Questions