Code covered by the BSD License  

Highlights from
Repeated Values

5.0

5.0 | 3 ratings Rate this file 10 Downloads (last 30 days) File Size: 1.88 KB File ID: #29692

Repeated Values

by

 

13 Dec 2010 (Updated )

Finds all repeated values for input X, and their attributes.

| Watch this File

File Information
Description

REPVAL Repeated Values
repval(X) finds all repeated values for input X, and their attributes.
The input may be vector, matrix, char string, or cell of strings
 
Y=repval(X) returns the repeated values of X
 
[RV, NR, POS, IR]=repval(X) returns the following outputs
RV : Repeated Values (sorted)
NR : Number of times each RV was repeated
POS : Position vector of X of RV entries
IR : Index of repetition
 
Example:
X=[1 5 5 9 5 5 1];
[RV,NR,POS,IR]=repval(X)

Output:
RV = [1 5]; %Numbers '1' and '5' are repeated values
NR = [2 4]; %Respectively repeated 2 and 4 times
POS = [1 7 2 3 5 6]; %Position index of X for repeated values
IR = [1 1 2 2 2 2]; %Corresponding to which index of RV
 
Vectors
[RV,NR,POS,IR]=repval([1 2 2 3 2 2 1])
 
Matrix (repeated rows)
[RV,NR,POS,IR]=repval([1 2; 3 4; 1 2; 1 3; 3 4])
 
Char String
[RV,NR,POS,IR]=repval('abracadabra')
 
Cell of Strings
[RV,NR,POS,IR]=repval({'bat','cat','car','bar','bat','car'})
 

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
10 Sep 2014 Xindi Li

really helpful, thanks!

28 Jan 2013 Timothy Russell  
25 Feb 2011 Jaime Undurraga

thanks, useful and practical.

Updates
13 Dec 2010

Included credit to J.S. from message board in which the code was expanded from

12 Sep 2011

Updated description and tags

04 Apr 2012

Updated help section

Contact us