4.0

4.0 | 1 rating Rate this file 99 downloads (last 30 days) File Size: 2.05 KB File ID: #12292

UNIQUEWITHEQUALNANS

by Jos

 

15 Sep 2006 (Updated 06 Apr 2009)

Code covered by BSD License  

Set unique, treating NaNs as equal (v2.0, mar 2009)

Download Now | Watch this File

File Information
Description

 UNIQUEWITHEQUALNANS - Set unique, treating NaNs as equal
    B = UNIQUEWITHEQUALNANS(A) for the array A returns the same values as in A
    but with no repetitions. B will also be sorted (NaNs as last).
 
    UNIQUEWITHEQUALNANS(A,'rows') for the matrix A returns the unique rows
    of A, treating NaNs as equal.
 
    [B,I,J] = UNIQUEWITHEQUALNANS(...) also returns index vectors I and J such
    that B = A(I) and A = B(J) (or B = A(I,:) and A = B(J,:)).
 
    [B,I,J] = UNIQUEWITHEQUALNANS(...,'first') returns the vector I to
    index the first occurrence of each unique value in A.
    UNIQUEWITHEQUALNANS(...,'last'), the default, returns the vector I to
    index the last occurrence.
 
    Example:
      A = [1 2 NaN ; 1 2 NaN ; 1 2 NaN] ;
      unique(A,'rows')
      % -> [1 2 NaN ; 1 2 NaN ; 1 2 NaN] ;
      uniquewithequalnans(A,'rows')
      %-> [1 2 NaN]
 
    For a cell array of strings, this function behaves exactly like UNIQUE.
 
    See also unique, ISEQUALWITHNANS.

v2.0, mar 2009 - update to deal with recent versions of UNIQUE

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
05 Apr 2009 Hoi Wong

Great tool. But you cannot just pass [] into unique as second argument. I modified it for my own use, but I'd encourage the original author to update it instead of having me posting a minor modification of your work. :)

06 Apr 2009 Jos

@Hoi Wong: apparently TMW changed the internals of UNIQUE, so it is no longer backward compatible. I will update this function shortly.

Please login to add a comment or rating.
Updates
06 Apr 2009

update to deal with recent versions of UNIQUE

Tag Activity for this File
Tag Applied By Date/Time
matrices Jos 22 Oct 2008 08:39:36
nan Jos 24 Oct 2008 15:35:10
sort Jos 24 Oct 2008 15:35:10
isequal Jos 24 Oct 2008 15:35:10
unique Jos 24 Oct 2008 15:35:10
compare Jos 24 Oct 2008 15:35:10
set Jos 24 Oct 2008 15:35:10
equal Jos 24 Oct 2008 15:35:10
utility Jos 24 Oct 2008 15:35:10
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com