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

50 visualizzazioni (ultimi 30 giorni)
laurie il 9 Mar 2015
Commentato: Star Strider il 9 Mar 2015
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?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Star Strider il 9 Mar 2015
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.
##### 2 CommentiMostra NessunoNascondi Nessuno
laurie il 9 Mar 2015
wow that's so cool. Thanks!
Star Strider il 9 Mar 2015
My pleasure!
Have fun with MATLAB!

Accedi per commentare.

### Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by