Find a row in a matrix

1 回表示 (過去 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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by