# finding the position of elements in a matrix if the elements are repeated

1 Ansicht (letzte 30 Tage)
sampath kumar punna am 30 Okt. 2019
Bearbeitet: Stephen23 am 30 Okt. 2019
X=[
148 124
189 147
119 121
160 144
160 102
133 125
63 99
104 122
141 112
182 135
112 109
153 132
103 90
144 113
145 87
97 110
124 114
165 137
95 111
136 134
180 92
109 115
39 89
141 112
160 102
133 125
63 99
104 122
123 80
164 103
121 77
73 100]
Y=[
39 89
63 99
63 99
73 100
103 90
121 77
95 111
97 110
123 80
112 109]
i want to know the position of Y values in X, as the vlaues in Y are repeated i coudn't get my right postion with is code
[~,loc,~] = intersect(X, Y ,'rows')
it gives me a location
23
7
32
19
16
13
11
31
29
its only correct for few elements and its giving wrong postion.
thank you
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
sampath kumar punna am 30 Okt. 2019
23
7
26
32
20
31
22
19
29
11
ME am 30 Okt. 2019
Bearbeitet: ME am 30 Okt. 2019
I don’t understand how your suggested output could be correct. Row 13 of X is in Y but 13 isn’t in your proposed correct solution.

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

ME am 30 Okt. 2019
You could use
pos = find(ismember(Z, M, 'rows') == 1);
instead, although as I have commented above, I don’t think your suggested correct solution is actually correct.
##### 2 KommentareKeine anzeigenKeine ausblenden
Stephen23 am 30 Okt. 2019
Bearbeitet: Stephen23 am 30 Okt. 2019
I agree that row 13 or X should be in the output. Well spotted.
Note that the ==1 is superfluous (all it does is convert false to false and true to true, as ismember already returns a logical output).
ME am 30 Okt. 2019
Thanks for pointing that out. I should have noticed that!

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by