How to compare two matrix?

2 次查看(过去 30 天)
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!

采纳的回答

Walter Roberson
Walter Roberson 2019-9-16
nnz(A == 1 & B == 3)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by