MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Learn moreOpportunities for recent engineering grads.
Apply TodayNew to MATLAB?
MATLAB Central > MATLAB Newsreader > Neighbor Indexing 

I want to write a function that changes the state of a randomly chosen cell in an mxn matrix based on the state of its 8 neighbors and itself. Because the cell will be randomly chosen, I must account for neighboring cells beyond the edge boundaries by having values picked up by wrapping around to another row and/or column. How do I do this? 
Use rand() to pick the cell location  the row, column in the cell 
Thank you for your prompt response, ImageAnalyst! I'm talking about an MxN grid of zeros and ones. If the majority of the 9 cells is 1, the updated cell becomes 0. If the majority of the 9 cells is 0, the updated cell becomes 1. My plan is to sum the states (0 or 1) of the 9 cells and if the sum is greater than or equal to 5, the majority is clearly 1 and the state will change to 0, etc. I understand how to create the random grid of zeros and ones and pick the random cell in the grid. What I am still confused about is how to incorporate the wrap around command within one loop. So far, I have accounted for the 9 cells when the chosen cell's neighbors are within the bounds: 
"Sarah Jones" <enewton6@gmail.com> wrote in message <icpj34$242$1@fred.mathworks.com>... 
Roger's solution looks good. If you want to do it for *every single 
The <a href="http://bestfinanceblog.com">loans</a> are useful for guys, which want to start their organization. As a fact, that is not very hard to receive a term loan. 
No tags are associated with this thread.
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.