Reorder symbols in helical pattern
intrlvd = helscanintrlv(data,Nrows,Ncols,hstep)
intrlvd = helscanintrlv(data,Nrows,Ncols,hstep) rearranges the elements in data by filling a temporary matrix with the elements row by row and then sending the matrix contents to the output in a helical fashion. Nrows and Ncols are the dimensions of the temporary matrix. hstep is the slope of the diagonal, that is, the amount by which the row index increases as the column index increases by one. hstep must be a nonnegative integer less than Nrows.
Helical fashion means that the function selects elements along diagonals of the temporary matrix. The number of elements in each diagonal is exactly Ncols, after the function wraps past the edges of the matrix when necessary. The function traverses diagonals so that the row index and column index both increase. Each diagonal after the first one begins one row below the first element of the previous diagonal.
If data is a vector, it must have Nrows*Ncols elements. If data is a matrix with multiple rows and columns, data must have Nrows*Ncols rows and the function processes the columns independently.
The command below rearranges a vector using diagonals of two different slopes.
i1 = helscanintrlv(1:12,3,4,1) % Slope of diagonal is 1. i2 = helscanintrlv(1:12,3,4,2) % Slope of diagonal is 2.
The output is below.
i1 = Columns 1 through 10 1 6 11 4 5 10 3 8 9 2 Columns 11 through 12 7 12 i2 = Columns 1 through 10 1 10 7 4 5 2 11 8 9 6 Columns 11 through 12 3 12
In each case, the function internally creates the temporary 3-by-4 matrix
[1 2 3 4; 5 6 7 8; 9 10 11 12]
To form i1, the function forms each slope-one diagonal by moving one row down and one column to the right. The first diagonal contains 1, 6, 11, and 4, while the second diagonal starts with 5 because that is beneath 1 in the temporary matrix.
To form i2, the function forms each slope-two diagonal by moving two rows down and one column to the right. The first diagonal contains 1, 10, 7, and 4, while the second diagonal starts with 5 because that is beneath 1 in the temporary matrix.