Code covered by the BSD License  

Highlights from
RANDPERMBREAK (v1.1, nov 2008)

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 2.53 KB File ID: #22008

RANDPERMBREAK (v1.1, nov 2008)

by Jos (10584)

 

05 Nov 2008 (Updated 06 Nov 2008)

randomize the order of elements within sections of a vector

| Watch this File

File Information
Description

R = RANDPERMBREAK(N, BP) returns a random permutation of the numbers 1
    to N in sections, using the breakpoints specified by the indices BP.
    If BP is a scalar, the first part of R contains a random permutation of
    the numbers 1 to BP(1) and the second part a random permutation of the
    numbers BP(1)+1 to N. Example:
 
      randpermbreak(10,5)
      % could return 1 5 3 4 2 10 8 7 6 9
    
    If BP contains more indices, the indices are used in sorted order, and
    R consists of a random permutation of 1 to BP(1), BP(1)+1 to BP(2), ...
    and BP(N) to N. Example:
 
      randpermbreak(12,[4 8])
      % 3 2 4 1 6 5 7 8 12 9 11 10
 
    RANDPERMBREAK(X,BP,'fixed') excludes the break point indiced from being
    permuted. Example:
 
      randpermbreak(7,4,'fixed')
      % a random permutation of 1 to 3, 4 and a permutation of 5-7
      % 3 1 2 4 7 5 6
   
    This function can be used to arbitrarily permute a list of characters,
    like in this example:
      T = ['Uijt!jt!bo!jmmvtusbujpo!pg!uif!fggfdu!pg!qfsnvujoh!mfuuf' ...
           'st!xjuijo!xpset!' char(14) '!fydfqu!gps!uif!gjstu!boe!mbtu!mfuufs!/' ...
           '!Ep!zpv!uijol!uiftf!tfoufodft!' char(14) '!bsf!tujmm!sfbebcmf!@'] ;
      i = find(T == 33) ;
      r = randpermbreak(numel(T),[1 i-1 i i+1 numel(T)],'fixed') ;
      char(T(r)-1)
 
    Notes:
    - Break point indices smaller than 1 or larger than the number of
      elements in N are ignored.
    - If BP is empty, the result will be a random permutation of the
      numbers 1 to N, just like randperm.
 
    See also randperm, rand, sort
             shake, randswap, sortbreak (File Exchange)

MATLAB release MATLAB 6.5 (R13)
Other requirements works on R13 and higher
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
06 Nov 2008 Jos (10584)

In v1.0 the last example should read:
T = ['Uijt!jt!bo!jmmvtusbujpo!pg!uif!fggfdu!pg!qfsnvujoh!mfuuf' ...
           'st!xjuijo!xpset!' char(14) '!fydfqu!gps!uif!gjstu!boe!mbtu!mfuufs!/' ...
           '!Ep!zpv!uijol!uiftf!tfoufodft!' char(14) '!bsf!tujmm!sfbebcmf!@'] ;
      i = find(T == 33) ;
      r = randpermbreak(numel(T),[1 i-1 i i+1 numel(T)],'fixed') ;
      char(T(r)-1)

Please login to add a comment or rating.
Updates
06 Nov 2008

fixed last example

Tag Activity for this File
Tag Applied By Date/Time
rand Jos (10584) 05 Nov 2008 21:54:45
sections Jos (10584) 05 Nov 2008 21:54:45
matrix manipulation Jos (10584) 05 Nov 2008 21:54:45
matrices Jos (10584) 05 Nov 2008 21:54:45
sort Jos (10584) 05 Nov 2008 21:54:45
order Jos (10584) 05 Nov 2008 21:54:45
shuffle Jos (10584) 05 Nov 2008 21:54:45
randomize Jos (10584) 05 Nov 2008 21:54:45
shake Jos (10584) 05 Nov 2008 21:54:45
matrix Cristina McIntire 10 Nov 2008 10:46:36
gps kuoping 29 Jun 2010 07:16:19

Contact us at files@mathworks.com