How to compare two matrix?

4 Ansichten (letzte 30 Tage)
Taoooooooooooo
Taoooooooooooo am 16 Sep. 2019
Beantwortet: Walter Roberson am 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!

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by