How can I check if row matrix B is equal to a row of matrix A?

17 次查看(过去 30 天)
I have a matrix A = [1 2 3; 4 5 6; 7 8 9]
I randomly generate matrix B = [4 5 6]
How can I check if B is a row of A in ONE loop or using NO loops?

采纳的回答

Star Strider
Star Strider 2015-3-9
Look Laurie! NO LOOPS!
A = [1 2 3; 4 5 6; 7 8 9];
B = [4 5 6];
[Result,LocResult] = ismember(B,A,'rows')
produces:
Result =
1
LocResult =
2
The ‘Result’ output indicates that there is a match, and ‘LocResult’ that the match is the second row.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by