Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Returns a matrix with a value of one randomly added.
- %In addition, popcorn returns the row-column coordinate where the latest piece popped
- function [pop loc] = popcorn(M)
- columns = length(M); %gives length of matrix columns
- rows = length(M(:,1)); %gives length of matrix rows
- random_column = randrange(columns); %chooses a random column
- random_row = randrange(rows); %chooses a random row
- loc = [random_column random_row]; %returns random coordinate
- M(random_column, random_row) = M(random_column, random_row) + 1; %add one at coordinate chosen
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement