Find rows in MATRIX based on position of elements
Afficher commentaires plus anciens
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 commentaires
waqas
le 26 Jan 2021
Do you know from where E is taken or is it would be another input that you need to find if it exists in the matrix?
Rishi Balasubramanian
le 26 Jan 2021
Jan
le 26 Jan 2021
Please post an example of the wanted output. You are searching for rows, but the pattern contains 2 rows. Does the column position matter?
Is the problem tiny? Then two loops can solve it efficiently.
Rishi Balasubramanian
le 26 Jan 2021
Modifié(e) : Rishi Balasubramanian
le 26 Jan 2021
Rishi Balasubramanian
le 26 Jan 2021
Rishi Balasubramanian
le 26 Jan 2021
Jan
le 26 Jan 2021
Sorry, I don't get it. How can the method for searching E in H know, that it should ignore the last two rows? You are not searching for the matrix E, but for flipud(E)? Or are the order of the rows of E arbitary? Does it matter, where the patterns occur in the searched rows?
Rishi Balasubramanian
le 26 Jan 2021
Jan
le 26 Jan 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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!