[Scilab-users] Get duplicates of a vector

classic Classic list List threaded Threaded
3 messages Options
hibr01 hibr01
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Get duplicates of a vector

Hello,
 
I want to get the duplicates of a vector. Lets say I have a vector as follows:
 
A = [ 1 5 3 2 3 1 ];
 
I want to get a vector which contains the duplicates [1 3].
 
I found intersect, union and unique but they give me just the vector w/o the duplicates. In this example unique(A)=>[1 2 3 5]. So I just need a function to compare the original vector A with the results of lets say unique(A) and return the remaining members. Can this be done vectorized w/o nested for-loops? Or is there a more elegant approach available?
 
Thx, Hani

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
RolandB RolandB
Reply | Threaded
Open this post in threaded view
|

Re: Get duplicates of a vector

Hi,


B=unique(A)(members(unique(A), A)==2);

Regards,
Roland



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
hibr01 hibr01
Reply | Threaded
Open this post in threaded view
|

Re: Get duplicates of a vector

Thank you for your quick response. That's it. You helped me a lot.
 
By changing ==2 to >=2 it also works when a number occurs more than twice.
 
Again many thanks, Roland.
 
Hani
 
Gesendet: Montag, 23. September 2019 um 19:43 Uhr
Von: "RolandB" <[hidden email]>
An: [hidden email]
Betreff: Re: [Scilab-users] Get duplicates of a vector
Hi,


B=unique(A)(members(unique(A), A)==2);

Regards,
Roland



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users