snake - %(going from top to bottom of column 1, bottom to...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function shifted=snake(input_array,number_shift) %function to shift the inputted array a number of places specified by %the input integer and return the resulting array; %the shifting will go down the first column, then up the second column and %so on; the last number in the array shifts by moving to the first place %in the array; shifting may go backwards if the second input is negative %usage: shifted=snake(input_array,number_shift) [r c]=size(input_array); %finds the number of rows and columns; this will be useful when we have to %reshape our array flip=reverseCols(input_array); %flips the even columns in the input_array; this will flip the even columns %so that the positions needed to shift the numbers in the form of a snake
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %(going from top to bottom of column 1, bottom to top of column 2, and %repeating the pattern until the end) will be correct col=flip(:); %will make the flip array a vertical column; this will make our changed %array a vertical column in order to perform the barrel shift function to %shift our array the desired number of times new=rotateVec(col,number_shift); %will barrel role the col array number_shift times shifted=reshape(new,r,c); %will linearize the shifted array; this will recreate our original array %with the shifted positions shifted=reverseCols(shifted); %will flip the even columns again; reshaping the array will make the...
View Full Document

Ask a homework question - tutors are online