How to find the position of a row in an array

2 visualizzazioni (ultimi 30 giorni)
Cantor Set il 15 Feb 2020
Commentato: Cantor Set il 15 Feb 2020
If I have an array like this
R=[1 0 1 1 1;
1 1 0 1 0;
1 0 1 1 0;
0 1 0 1 1;
0 0 1 0 1];
I want to find the position of S in R.
S=[1 0 1 1 0];
Is there a function which takes S as an input and returns me its position in R which is the 3rd row
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Risposte (2)

JESUS DAVID ARIZA ROYETH il 15 Feb 2020
rows=find(all(R==S,2))
0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Stephen23 il 15 Feb 2020
>> [~,Y] = ismember(S,R,'rows')
Y = 3
1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Cantor Set il 15 Feb 2020
but what if S exists in 2 different rows:
R=[1 1 1; 1 1 1; 2 2 2];
[~,Y] = ismember(S,R,'rows')
Y=1
can it be refiend so that it returns Y=[1 2] ?

Accedi per commentare.

Categorie

Scopri di più su Multidimensional Arrays 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