selecting submatrix of like elements

1 次查看(过去 30 天)
Bahar
Bahar 2014-4-25
评论: Bahar 2014-4-26
I need to be able to search a matrix for a submatrix of like elements and then manipulate that group of like elements. For example:
A= [0 0 0 0 0; 0 1 1 0 0; 0 1 1 0 0; 0 0 0 0]
I would like to be able to get at
B= [1 1, 1 1]
and then I would like to randomly move B within A.
The purpose of this is to make a quick demo where I get some tiles to conditionally stick together during a random walk and form larger structures which in turn rotate and move randomly.

回答(1 个)

Walter Roberson
Walter Roberson 2014-4-25
Are the values integers? If so then using the image processing toolbox would possibly be easiest. You can use bwlabel() to find the "islands" in flexible ways, using 4-connection (must be left or right, or up or down) or 8-connection (diagonals allowed) or other custom rules. regionprops() can then give you information about the blobs including lists of coordinates.
  1 个评论
Bahar
Bahar 2014-4-26
Thank you - this was actually very helpful. I can now find and move the 'islands' in my matrix. Unfortunately, the only way I can move them is 'element by element' which causes them to come apart if they hit some obstruction (as a move isnt legal unless the spot its going to is 0).
You dont happen to know of any way to move like numbers as a unit?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Denoising and Compression 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by