nnz(A == 1 & B == 3)
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!
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!