Find a row in a matrix

2 次查看(过去 30 天)
Miguel Cardoso
Miguel Cardoso 2020-4-21
回答: Rik 2020-4-21
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

采纳的回答

Rik
Rik 2020-4-21
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);

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by