필터 지우기
필터 지우기

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