intrlv

Reorder sequence of symbols

Description

example

intrlvd = intrlv(data,elements) rearranges the elements of data without repeating or omitting any elements. If data is a length-N vector or an N-row matrix, elements is a length-N vector that permutes the integers from 1 to N. The sequence in elements is the sequence in which elements from data or its columns appear in intrlvd. If data is a matrix with multiple rows and columns, the function processes the columns independently.

Examples

collapse all

Use the intrlv function to rearrange the elements of a vector to a random permutation determined by the randperm function.

p = randperm(10); % Permutation vector
a = intrlv(10:10:100,p)
a = 1×10

60    30    70    80    50    10    20    40    90   100

The command below rearranges each of two columns of a matrix.

b = intrlv([.1 .2 .3 .4 .5; .2 .4 .6 .8 1]',[2 4 3 5 1])
b = 5×2

0.2000    0.4000
0.4000    0.8000
0.3000    0.6000
0.5000    1.0000
0.1000    0.2000

Use the intrlv function to rearrange the elements of a matrix to a specified order.

Each column of the matrix applies the same reordering.

b = intrlv([.1 .2 .3 .4 .5; .2 .4 .6 .8 1]',[2 4 3 5 1])
b = 5×2

0.2000    0.4000
0.4000    0.8000
0.3000    0.6000
0.5000    1.0000
0.1000    0.2000