Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. %Returns a matrix with a value of one randomly added.
  2. %In addition, popcorn returns the row-column coordinate where the latest piece popped
  3. function [pop loc] = popcorn(M)
  4.  
  5. columns = length(M); %gives length of matrix columns
  6. rows = length(M(:,1)); %gives length of matrix rows
  7.  
  8. random_column = randrange(columns); %chooses a random column
  9. random_row = randrange(rows); %chooses a random row
  10.  
  11. loc = [random_column random_row]; %returns random coordinate
  12. M(random_column, random_row) = M(random_column, random_row) + 1; %add one at coordinate chosen
  13.  
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement