Code covered by the BSD License  

Highlights from
MYUNIQUE

4.25

4.2 | 4 ratings Rate this file 13 Downloads (last 30 days) File Size: 1.43 KB File ID: #15242

MYUNIQUE

by Mehmet OZTURK

 

09 Jun 2007 (Updated 20 Jun 2007)

finds uniqe entries, indices and number of occurances of the unique elements

| Watch this File

File Information
Description

MYUNIQUE is a function to find unique elements in a numeric vector in the order in which they appear first or last which is determined by "mode" (default is first). The function is also outputs the indices "ndx" of unique elements and number of occurances of that elements in "h".

% Example:
% >> a=[9 3 6 2 7 1 2 1 1 1 9 9 3 3];
% >> [b ndx h]=myunique(a)
% b =
%
% 9 3 6 2 7 1
% ndx =
%
% 1 2 3 4 5 6
% h =
%
% 3 3 1 2 1 4
%
% >> myunique(a,'last')
% ans =
%
% 6 7 2 1 9 3

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
11 Jun 2007 Richard Brown

Yet another "myunique" posted to the file exchange, which is the same as unique, but with unsorted output. This is the third in a week - is this a homework assignment?

Stating that it returns "unsorted" output sounds to anyone who reads it that it should perform better than unique as it doesn't sort the values.

This is in fact not the case, what the code does is return the unique elements in the order in which they appear, which takes more effort than unique (two sorts used in this code, for instance). The code can also return the indices of these first (or last) appearing values but this isn't stated in the help, although this would be probably one of the submission's most useful features.

Clear up the documentation, and state the point to improve it

>> x = floor(100 * rand(1, 1000000));
>> tic, a = unique(x); toc
Elapsed time is 0.301613 seconds.
>> tic, b = myunique(x); toc
Elapsed time is 0.730075 seconds.

13 Jul 2007 JK L

very useful

27 Aug 2009 José-Luis Guerrero

Works like a charm

26 Oct 2011 Reza Farrahi Moghaddam  
Please login to add a comment or rating.
Updates
20 Jun 2007

Added property to find number of occurances.

Tag Activity for this File
Tag Applied By Date/Time
matrices Mehmet OZTURK 22 Oct 2008 09:15:01
unique Mehmet OZTURK 22 Oct 2008 09:15:01
not sorted output Mehmet OZTURK 22 Oct 2008 09:15:01
histogram Mehmet OZTURK 22 Oct 2008 09:15:01

Contact us at files@mathworks.com