snake - % array as a vector) % Examples: % x = snake([1 2 3...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 % Write a function called snake that takes in an array and a number % indicating how many places to "snake" the array as described below. % Snaking the vector involves shifting the numbers down columns, and % appending the overflow onto the top of the next column. The overflow from % the last column must go into the top of the first column. % Hint: Use array linearization (it is very difficult unless you treat the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % array as a vector) % Examples: % x = snake([1 2 3 % 4 5 6 % 7 8 9], 2) % x -> [6 4 5 % 9 7 8 % 1 2 3] % x2 = snake([4 7 9 % 3 1 8], 1) % x2 -> [8 3 1 % 4 7 9] function Z = snake(A,num) [row col] = size(A) Z = A x = row * col if num > x num = num - x end for i = 1:(x-num) Z(i + num) = A(i) end for i = (x-num+1):x Z((x-(i+num)) * -1) = A(i) end...
View Full Document

This note was uploaded on 07/06/2009 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Institute of Technology.

Ask a homework question - tutors are online