Search a given row array in a matrix and get position

조회 수: 1 (최근 30일)
M Azpiroz
M Azpiroz 2021년 10월 11일
댓글: M Azpiroz 2021년 10월 11일
I am trying to find the ch = ones(1,9)*178 row array in a large matrix. In that matrix, the number 178 on its own appears in many positions but I want to find the positions when the 9-element array with 178 occurs. If the matrix were A=[0 0 0 0 0 0 0 0 0 178 0 0 0 0 0; 1 2 5 3 2 4 178 5 6 2 2 2 2 2 2; 0 2 178 178 178 178 178 178 178 178 178 0 2 3 2]; the result should be row = 3, column =3. I guess ismember must be in the code but I can´t figure out how... Thanks!

채택된 답변

KSSV
KSSV 2021년 10월 11일
A=[0 0 0 0 0 0 0 0 0 178 0 0 0 0 0; 1 2 5 3 2 4 178 5 6 2 2 2 2 2 2; 0 2 178 178 178 178 178 178 178 178 178 0 2 3 2];
ch = ones(1,9)*178 ;
for i = 1:size(A,1)
idx = strfind(A(i,:),ch)
end
idx = [] idx = []
idx = 3
  댓글 수: 1
M Azpiroz
M Azpiroz 2021년 10월 11일
Of course! Much easier than my previous trials! Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by