Code covered by the BSD License  

Highlights from
SORTBREAK (v1.0, nov 2008)

Be the first to rate this file! 1 Download (last 30 days) File Size: 2.53 KB File ID: #22007

SORTBREAK (v1.0, nov 2008)

by Jos (10584)

 

05 Nov 2008

sort elements of a vector between break points

| Watch this File

File Information
Description

Y = SORTBREAK(X,BP) sorts the elements within sections of the vector X
     in ascending order. The sections are defined by the breakpoint
     indices BP. Each section is sorted independently.
 
     If BP is a single index, the two sections are X(1:BP) and X((BP+1):end).
     Example:
 
       Y = sortbreak([5 3 7 1 4 2 8 6],4)
       % Y -> [1 3 5 7 2 4 6 8]
 
     If BP contains more indices, the indices are used in sorted order, and
     the first section contains the elements X(1:BP(1)), the second
     section contains the elements X(BP(1)+1:BP(2)), etc. The last
     section contains the elements X(BP(end)+1:end). Example:
 
       Y = sortbreak([5 3 7 1 4 2 8 6],[2 6])
       % Y -> [3 5 1 2 4 7 6 8]
 
     SORTBREAK(X,BP,'fixed') excludes the break points from sorting. Example:
 
       % sort between zeros
       X = [3 1 2 0 3 1 -4 0 6 4 7 0 5 3] ;
       Y = sortbreak(X,find(X==0),'fixed')
       % Y -> [1 2 3 0 -4 1 3 0 4 6 7 0 3 5]
       % whereas Y = sortbreak(X,find(X==0))
       % would yield [0 1 2 3 -4 0 1 3 ...]
   
     [Y,I,J] = SORTBREAK(X,BP) returns sorting indices I and J such that
     that Y equals X(I) and X equals Y(J).
 
     Notes:
     - Break point indices larger than the number of elements in X are
       ignored.
     - If BP is empty, the whole vector is sorted.
     - For arrays, X is treated as a vector, but Y, I and J will have the
       same size as X.
     - To sort between NaNs, the third argument 'fixed' is not needed as
       NaNs are always sorted at the end of the sublist
         X = [3 1 2 NaN 3 1 -4 NaN 6 4 7 NaN 5 3] ;
         Y = sortbreak(X,find(isnan(X)))
         % Y -> [1 2 3 NaN -4 1 3 NaN 4 6 7 NaN 3 5]
 
     See also : sort, sortrows, issorted
                randpermbreak (File Exchange)

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.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
sort Jos (10584) 05 Nov 2008 21:54:34
sections Jos (10584) 05 Nov 2008 21:54:34
vector Jos (10584) 05 Nov 2008 21:54:34
break Jos (10584) 05 Nov 2008 21:54:34
partial Jos (10584) 05 Nov 2008 21:54:34
matrices Jos (10584) 05 Nov 2008 21:54:34
matrix manipulation Jos (10584) 05 Nov 2008 21:54:34

Contact us at files@mathworks.com