coding the way of selection between two matrices
Mostrar comentarios más antiguos
Hi I have two matrices A and B. the dimension of These matrices is (m x n). I want to find the pattern of selection in which I allocate value 1 for selection and value 0 for non selection in such a way that if I select one cell for example cell(m=2 and n=3) in matrix A and allocate 1 to it, the value of 4 cells that are around it in matrix B will be 1 and the other cells will be 0. this pattern of selection must be applied for all cells in matrix A and therefore must be done for cells in matrix B.
For example if I have matrix A (3 x 3) and read it like image, if I select the first cell and allocate 1 to it. in matrix B I must allocate 1 to cells 2 and 4. I must do the pattern for all cells.

can you help me please?
5 comentarios
Guillaume
el 22 de Nov. de 2014
I'm afraid I didn't understand what you want to do. Could you give small examples of A and B, the result you expect and show the first few steps of your algorithm that lead to it.
fatema saba
el 22 de Nov. de 2014
fatema saba
el 23 de Nov. de 2014
Guillaume
el 23 de Nov. de 2014
What do you mean by 'selected'? There's no concept of selection in matlab. You could extract the elements (in what?), change their value (to what?), get their indices, etc. but select on its own doesn't mean anything.
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 23 de Nov. de 2014
0 votos
Looks like a standard "game of life" sort of thing. Perhaps the File Exchange will give you ideas: http://www.mathworks.com/matlabcentral/fileexchange/index?utf8=%E2%9C%93&term=game+of+life
3 comentarios
fatema saba
el 23 de Nov. de 2014
Image Analyst
el 23 de Nov. de 2014
See http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life Basically you change a element (pixel) and then surrounding elements change in a manner according to some rules you set up. Like the north, south, east, and west pixels get set to 1 (I think that's your rule). Then you can apply the rules on those pixels, or on any remaining pixels. With your rule, won't the whole array eventually be 1?
fatema saba
el 23 de Nov. de 2014
fatema saba
el 23 de Nov. de 2014
2 comentarios
Roger Stafford
el 23 de Nov. de 2014
Editada: Roger Stafford
el 23 de Nov. de 2014
You need to change the first two inequalities to allow equality:
if jB+1<=n
....
if iB+1<=m
....
Otherwise 1's won't be entered into either the last column or the last row.
Also why have two nested for-loops when the only action occurs when r == c? You could do the same thing with just the "for r = 1:m*n" loop alone.
And finally, that last operation "B = zeros(m,n)" would undo all your good work. What is it doing there?
fatema saba
el 24 de Nov. de 2014
Categorías
Más información sobre Conway's Game of Life en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



