From: alfann on 8 Jun 2010 06:37 Hi there, small question please.. if I have this matrix: U3=[0 1 0 0 0; 0 1 0 0 0; 0 1 0 0 0; 0 1 1 0 0; 0 0 1 1 0; 0 0 0 1 0; 0 0 0 1 0; 0 0 0 1 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1] in this matrix, I do some calculations then change one value in U3 matrix to one. The ones start from the top to the bottom. I want stop my calculations when the ones are in one chain from the top to the bottom. How can I do that please? Note: It could be go vertically direction, horizontally or diagonally direction as it has been shown in the above example. Please help me.
From: Walter Roberson on 8 Jun 2010 11:59 alfann wrote: > if I have this matrix: > U3=[0 1 0 0 0; 0 1 0 0 0; 0 1 0 0 0; 0 1 1 0 0; 0 0 1 1 0; 0 0 0 1 0; 0 0 0 1 0; 0 0 0 1 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1] > in this matrix, > I do some calculations then change one value in U3 matrix to one. > The ones start from the top to the bottom. > > I want stop my calculations when the ones are in one chain from the top to the bottom. How can I do that please? > Note: > It could be go vertically direction, horizontally or diagonally direction as it has been shown in the above example. Hint: any(all(U3,1)) || any(all(U3,2)) takes care of the horizontal and vertical checks. You should be able to code a diagonal check once you decide whether you are interested only in the main diagonal, or the main diagonal together with the main anti-diagonal, or in any diagonal, or in any anti-diagonal...
From: alfann on 8 Jun 2010 08:24 Unfortunately, The code that you gave me is only work in vertical direction. I want it to work for this matrix: U3=[0 1 0 0 0; 0 1 0 0 0; 0 1 0 0 0; 0 1 1 0 0; 0 0 1 1 0; 0 0 0 1 0; 0 0 0 1 0; 0 0 0 1 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1] which ones started from the top to the bottom but not in vertical direction.
From: alfann on 8 Jun 2010 10:03 Please help me for it. waiting for you.
From: dpb on 8 Jun 2010 14:39 alfann wrote: > Unfortunately, The code that you gave me is only work in vertical > direction. I want it to work for this matrix: U3=[0 1 0 0 0; 0 1 0 0 > 0; 0 1 0 0 0; 0 1 1 0 0; 0 0 1 1 0; 0 0 0 1 0; 0 0 0 1 0; 0 0 0 1 1; > 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1; 0 0 0 0 1] > > > which ones started from the top to the bottom but not in vertical > direction. My thought would be [idx,jdx]=find(U3); process above to determine if is adjacency in M:N for allowable starting points. There are some shortcuts that can negate a solution I can see, of course. For the example, column one can be deleted reducing size. Second, if all on any row are 0, the path is broken (iiuc). Hence, you can eliminate any array for which any(~any(U3,2)) is nonzero After that, it's fairly much just checking nearest neighbors for continuity. --
|
Next
|
Last
Pages: 1 2 Prev: extract data from image-histogram as two x,y-data Next: exist() for a substructure |