How to compare two matrix?

4 visualizaciones (últimos 30 días)
Taoooooooooooo
Taoooooooooooo el 16 de Sept. de 2019
Respondida: Walter Roberson el 16 de Sept. de 2019
Hi all,
I have 2 different matrix A and B. I am wondering how to write a script to find how many times does a 1 in matrix A line up with 3 in matrix B. As we can see, in this case, there are 6 times where 1 in matrix A line up with 3 in matrix B, and their locations are all in the first column (Bolded 3 in the matrix B).
A =
[1 1 1 1 1 1 1 1 1 1
1 2 2 2 2 2 2 2 2 1
1 2 3 3 3 3 3 3 2 1
1 2 3 4 4 4 4 3 2 1
1 2 3 4 5 5 4 3 2 1
1 2 3 4 5 5 4 3 2 1
1 2 3 4 4 4 4 3 2 1
1 2 3 3 3 3 3 3 2 1
1 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 1 1];
B =
[1 1 1 1 1 1 1 1 0 0
2 2 2 2 2 2 2 1 0 0
3 3 3 3 3 3 2 1 0 0
3 4 4 4 4 3 2 1 0 0
3 4 5 5 4 3 2 1 0 0
3 4 5 5 4 3 2 1 0 0
3 4 4 4 4 3 2 1 0 0
3 3 3 3 3 3 2 1 0 0
2 2 2 2 2 2 2 1 0 0
1 1 1 1 1 1 1 1 0 0];
Please help~
Thank you!

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Sept. de 2019
nnz(A == 1 & B == 3)

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by