How to compare two matrix?

5 vues (au cours des 30 derniers jours)
Taoooooooooooo
Taoooooooooooo le 16 Sep 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!

Réponse acceptée

Walter Roberson
Walter Roberson le 16 Sep 2019
nnz(A == 1 & B == 3)

Plus de réponses (0)

Catégories

En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by