Search a given row array in a matrix and get position

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2021년 10월 11일

댓글:

2021년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by