0

I was using "intersect" in my Matlab code where I want the following:

A = [ 4 1 1 2 3];

[B] = sort(A, 'ascend'); % so that B is sorting A in ascending order, so I got B = [1 1 2 3 4]

[same,a] = intersect(B,A);

I want same = [1 1 2 3 4] but the simulation gives me same = [1 2 3 4] by omitting the repeated '1'.

I understand by using intersect it will return data with no repetition

C = intersect(A,B) returns the data common to both A and B with no repetitions. I want it to show the complete data including those repetition, what are the alternatives I can use rather than the function "intersect"?

For example:

A = [ 4 1 1 2 3];

[B] = sort(A, 'ascend'); % so that B is sorting A in ascending order, so I got B = [1 1 2 3 4]

[same,a] = intersect(B,A);

So now I want it to be like this same =[1 1 2 3 4] and a=[2 3 4 5 1].

I need to access ‘a’ where ‘a’ shows the original index prior to sorting so I can use it for further processing.

Thank you very much.

user2563812
  • 219
  • 1
  • 2
  • 12

1 Answers1

0

Why do you need intersect of A and B knowing that B contains the same values than A ? From what you said, I think you have all the needed results in B.

  • Sorry Guillaume, you are right, I should have made it clearer, please refer to my edited question, thanks for your time – user2563812 Oct 16 '13 at 10:45