Clear Filters
Clear Filters

set number 1 in binary matrix

3 views (last 30 days)
Firas Al-Kharabsheh
Firas Al-Kharabsheh on 3 Apr 2016
Edited: Image Analyst on 3 Apr 2016
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 Comments
Firas Al-Kharabsheh
Firas Al-Kharabsheh on 3 Apr 2016
for example the A(3,1) have 1 then return to matrix D(3,1) AND check if this 1 have neighbor beside it if true then return to C(3,1) the 1 and it's neighbor
Image Analyst
Image Analyst on 3 Apr 2016
Edited: Image Analyst on 3 Apr 2016
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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 3 Apr 2016
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] ?

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!