coding the way of selection between two matrices
古いコメントを表示
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 件のコメント
Guillaume
2014 年 11 月 22 日
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
2014 年 11 月 22 日
fatema saba
2014 年 11 月 23 日
Guillaume
2014 年 11 月 23 日
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.
採用された回答
その他の回答 (2 件)
Image Analyst
2014 年 11 月 23 日
0 投票
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 件のコメント
fatema saba
2014 年 11 月 23 日
Image Analyst
2014 年 11 月 23 日
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
2014 年 11 月 23 日
fatema saba
2014 年 11 月 23 日
2 件のコメント
Roger Stafford
2014 年 11 月 23 日
編集済み: Roger Stafford
2014 年 11 月 23 日
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
2014 年 11 月 24 日
カテゴリ
ヘルプ センター および File Exchange で Conway's Game of Life についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



