How to return a row from a 2d matrix
Afficher commentaires plus anciens
If i have a matrix like this A =
52 53 17 10 8
16 12 7 14 23
24 90 1 19 36
4 3 21 11 18
and
B = 30 52 7 10 80
5 20 22 7 43
4 2 1 9 6
and i want to get the intersection between them and whenever there is an
intersection, i want it to print the row that contains the intersected element
in A.
Like here for example, 52 is in both matrices, so one of the outputs should be:
52 53 17 10 8
My code:
A= [52 53 17 10 8; 16 12 7 14 23; 24 90 1 19 36; 4 3 21 11 18]
B= [30 52 7 10 80;5 20 22 7 43; 4 2 1 9 6]
r = intersect(A,B); %The values of intersection between the two matrices
for i = 1 : length(r)
m = find(A == r(i)); %This gets the indices where they intersect
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!