set number 1 in binary matrix
1 次查看(过去 30 天)
显示 更早的评论
if i have (NxM) matrix D and A
D = [ 1 0 1 0 1
0 1 0 1 1
1 1 1 0 0
1 0 0 1 1
1 1 0 0 1 ]
After apply some condition then A produced
A = [ 1 0 1 0 1
0 0 0 0 1
1 0 0 0 0
1 0 0 0 1
1 1 0 1 1 ]
i need a function to compare between D AND A
- if ( the last Or first column ) or ( first or last row ) in A having 1 then return to D matrix and if the D matrix in the last column having a 1 beside the 1 then put in A the number of one beside it
for example
C = [ 1 0 1 0 1
0 0 0 1 1
1 1 1 0 0
1 0 0 1 1
1 1 0 1 1 ]
4 个评论
Image Analyst
2016-4-3
编辑:Image Analyst
2016-4-3
Clear as mud. I guess return means "go back to"??? So if A(3,1) is 1, then you go back to D(3,1) and check if that is also 1? And if D(3,1) has any of it's neighbors (which could be as few as 3 if the D element is in a corner, or as many as 8 if the D element is in the middle of D) are also 1, then go back to matrix C and set the (3,1) element of C a 1 plus another 1 for all the neighbors that are also 1. So that element of C could either be untouched, OR could need to have as many as 9 1's put into C at the corresponding location. The only way C can hold more than one number is if C is a cell array.
So let's look at an actual example. Let's inspect location 3,1. Okay, A = 1 there, so we continue. Now we look at D(3,1). D(3,1) is also 1, so we continue. D(3,1) has 3 neighbors that are 1. So we need to go back to C and make it 1 plus the neighbors (whatever that means). So, do we set C(3,1) equal to 1+3 = 4? Or do we set C(3,1) equal to the array [1,1,1,1] which is a one plus 3 more 1's - one for each neighbor?
Well you had neither of those. You had C(3,1) equal to 1. So, is C maybe just equal to the AND of A and D? C = A&D? No, it's not. Maybe the OR? No, it's not that either. It appears C is the same as D except that the (5,4) element got changed to 1. I'm just not sure what the rule is.
回答(1 个)
Walter Roberson
2016-4-3
No, if that was your definition of B, then since the first two rows of A are the same, their corresponding rows in B must be the same, but rows 1 and 2 of B are different.
You have also not defined what is to be done when there are leading zeros in A. Or does that not matter and only the length of the runs are important? If so then why wouldn't the first two rows of B be either [1 0] or [0 1] ?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!