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!

 Accepted Answer

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

More Answers (0)

Categories

Asked:

on 11 Oct 2021

Commented:

on 11 Oct 2021

Community Treasure Hunt

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

Start Hunting!