Hello everybody, i would like to know how to find the position of elements of a matrix who are in another matrix. For example, letting i have two matrix A and B:
A= [2 1 2 3 2 5 4 7 5 4 8 10]B= [4 7 5 2 8 10 4 1 2 3 2 5]
I would like the output to provide the position of the elements of the B matrix that are present in the A matrix considering also repeated values.
For example "it finds in which position the element B (1,1) is present in the matrix A (:, 1), in which position the element B (2,1) is present in the matrix A (:, 1), in which position the element B (3,1) is present in the matrix A (:, 1) and so on ". So similarly for the other columns "find in which position the element B (1,2) is present in the matrix A (:, 2) etc"
Regarding the repetition I would like to make sure that if, for example, there are 3 repetitions in a column, each repetition will have an increasing order index, ie:
A= [ 2444]B=[4244]output=[2134 ]
I tried to use the MATLAB function "intersect", but it give as outputs only the indexes of the columns whose values are not repeated.
for n=1:size(A,2) [C, idx1, idx2] = intersect( B(:,n), A(:,n), 'stable');end
I do not know if I've been clear. Sorry.
Best Answer