MATLAB Answers

finding the position of values in a matrix

3 views (last 30 days)
sampath kumar punna
sampath kumar punna on 30 Oct 2019
i have set
X=[
12 14
1 2
12 4
6 14
12 18
12 4
1 2]
Y=[
1 2
1 2
6 14
12 4]
can i get the position of Y elements in X matrix as the number are repeated its hard for me to find using code normal code. can any one please help me.

  0 Comments

Sign in to comment.

Answers (1)

galaxy
galaxy on 30 Oct 2019
Try
[~,idx]=setdiff(X,Y,'rows');
idx_rows=setdiff(1:size(X,1),idx);
idx_rows =
2 3 4 6 7

  3 Comments

sampath kumar punna
sampath kumar punna on 30 Oct 2019
sorry, i have only 4 rows in my Y matrix how can i get 5 postions
galaxy
galaxy on 30 Oct 2019
because X and Y array has same value, if you want to find only one, you need use unique function
sampath kumar punna
sampath kumar punna on 30 Oct 2019
yes X and Y have same values but Y is not having all values of X only few values are in Y, so for those some values in Y, what is the position in X.

Sign in to comment.

Sign in to answer this question.