how to check if two arrays intersect within a matrix?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
roshan varkey
il 7 Dic 2013
Commentato: Image Analyst
il 8 Dic 2013
i have a 10x10 matrix of zeros.
three ships called destroyer,aircraft_carrier and cruiser:
destroyer=[2,2] %placed either vertically or horizontally within the matrix
cruiser=[4,4,4,4]%placed either vertically or horizontally within the matrix
aircraft_carrier=[5,5,5,5,5] %placed either vertically or horizontally within the matrix
i wrote the code so that the ships are placed randomly and also in a random alignment,vertical or horizontal.i want to check weather they intersect with each other so i can write code to prevent it.
i tried using intersect(a,b) command but it gave me back an empty matrix even when the point where intersecting..i dont know what i am doing wrong or if there is some other command to help me do this.....
0 Commenti
Risposta accettata
Image Analyst
il 7 Dic 2013
Modificato: Image Analyst
il 7 Dic 2013
Try this:
blankElements = (matrix1 == 0) & (matrix2 == 0);
matrixIntersections = (matrix1 ~= matrix2) & ~blankElements;
4 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!