Effacer les filtres
Effacer les filtres

Find a row in a matrix

2 vues (au cours des 30 derniers jours)
Miguel Cardoso
Miguel Cardoso le 21 Avr 2020
Réponse apportée : Rik le 21 Avr 2020
Hi!
I have a generic matrix with random numbers (-1 and +1).
M=[ 1 -1 1 -1
1 1 1 -1
-1 1 -1 1 % <----- this row
1 1 -1 1];
How can I extract a row index?
a=[-1 1 -1 1];
idx=3;
Thank you

Réponse acceptée

Rik
Rik le 21 Avr 2020
Assuming you have that vector already:
M=[ 1 -1 1 -1
1 1 1 -1
-1 1 -1 1 % <----- this row
1 1 -1 1];
a=[-1 1 -1 1];
tmp=abs(M-a);%uses implicit expansion, works in R2016b and newer
tmp=sum(tmp,2) <= eps;
idx=find(tmp);

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by