Find rows in MATRIX based on position of elements

7 visualizaciones (últimos 30 días)
Consider I have a binary matrix H
H = [1 1 0 1 1 0 0 1 0 1;
0 0 0 1 0 1 0 0 1 1;
0 1 1 0 1 0 1 0 0 1;
1 1 0 0 0 0 1 0 1 1;
0 0 1 0 0 1 0 1 0 1];
From this Matrix I am supposed to select a part which becomes E matrix
E = H(4:end, 8:end);
E = [0 1 1;
1 0 1];
Now what I need is - I need to find the rows in H which have 1s in positions equal to the positions of 1s in E
How do I achieve this in a simple way. Please help, people...
Edit - Basically the answer I need is row 1 and 2. How do I get it?
  10 comentarios
Rishi Balasubramanian
Rishi Balasubramanian el 26 de En. de 2021
Order of rows of E are not arbitrary. E is a selection of H. I don't want anything to do in E. But i want to find the rows(1 to 4) which have values exactly same as the ones in E(Consider the columns indices of E as 8, 9, 10 itself)
Jan
Jan el 26 de En. de 2021
If you are searching for the pattern:
E = [0 1 1;
1 0 1];
in the matrix:
H = [1 1 0 1 1 0 0 1 0 1;
0 0 0 1 0 1 0 0 1 1;
0 1 1 0 1 0 1 0 0 1;
1 1 0 0 0 0 1 0 1 1;
0 0 1 0 0 1 0 1 0 1];
you cannot find a matching matrix in the rows 1 and 2. As you writer: Row 1 ist matching row 5 and rows 2 is matching row 4. This means, you are looking for the E flipped vertically? This does not match the explanation "I don't want anything to do in E".
Or in other words: The pattern E does not appear anywhere in H except for the original location E were taken from.
If you know in advance, that you do not care about matchs in some specific lines, you are not searchung in H, but in H(1:end-2, :).
I suggest to restart from scratch. Obviously the leven of confusion is high. Then take a coffee and solve a sudoku. Afterwards take the time to explain clearly, what the inputs are and what you are exactly looking for. It is always harder to explain, when you know exactly what you want, because this makes it harder to imagine, that others do not have the faintest idea of it.

Iniciar sesión para comentar.

Respuesta aceptada

Shubham Khatri
Shubham Khatri el 3 de Feb. de 2021
Hello,
To my understanding you want to find the row number in the matrix H when there is match in matrix E.
To do this, I have converted the row of both matrix H and E in a string and then have compared them. If the value returned is a positive number, we display the row number. I have done this using 2 for loops. You can also locate the element number if you remove the size from s1 variable.
clc
H = [1 1 0 1 1 0 0 1 0 1;
0 0 0 1 0 1 0 0 1 0;
0 1 1 0 1 0 1 0 0 1;
1 1 0 0 0 0 1 0 1 1;
0 0 1 0 0 1 0 1 0 1];
E = H(4:end, 8:end);
for j=1:length(E(:,1))
a=E(j,:)
for k=1:length(H(:,1))
b=H(k,:);
s=num2str(a);
t=num2str(b);
s= s(find(~isspace(s)));
t= t(find(~isspace(t)));
s1=size((strfind(t,s)));%comparing
if s1>0
disp(k)
end
end
end
Hope it helps

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by