how to determine starting location of longest zero pan in a column
1 view (last 30 days)
Show older comments
Monika Kok
on 24 Apr 2016
Commented: Image Analyst
on 24 Apr 2016
g0 = [1 1 0 1 0 0 0 1 0 0 0 0 0 0 0]; %polynomial
genmat = gallery('circul' , g0) % making the circulant matrix
[r,c] = size(genmat);
for i = 1:c
s= genmat(:,1)
[pos1] = find(s==1)
% this is providing me location of ones but how can i find the zero's between those ones
% starting with column 0, i need to calculate the zero span. from the generated matrix you can see for column 0,maximum number of continuous zero is 7 which starts from position 1. now going for column 1 [ column 1 = column0 + column 1 ] which is giving zero span of 6 starting at position 2. for column 2 possibilities are: [c2 = c0+c2, c2=c0+c1+c2] will provide a zero span of 5 starting at position 3.
CONDITIONin summary we can say at c0 maximum zero span will start from position 1 and with every increase in column, zero span will decrease by 1 and shift to the next position. similarly [c3= c0+c3, c3=c0+c1+c3, c3=c0+c2+c3, c3= c0+c1+c2+c3][consider all possibilities]
if any column breaks the above defined condition, that column will be my answer
0 Comments
Accepted Answer
Image Analyst
on 24 Apr 2016
Isn't this what (the badly-named) "a" is in your other question: http://www.mathworks.com/matlabcentral/answers/280693-how-to-count-the-number-of-zeros-between-2-one-s so don't you already know how to get the length of the longest stretch of zeros?
2 Comments
Image Analyst
on 24 Apr 2016
You almost had it. You just needed to ask for the 'PixelIdxList' when you called regionprops. This gives you the index of every element in each grouping of 0's.
num = [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0];
% Measure the lengths of the stretches/runs of zeros.
measurements = regionprops(logical(~num), 'Area', 'PixelIdxList');
zerospan = [measurements.Area]
% Get index of the largest run in the lengths array:
[longestRun, indexOfLongestRun] = max(zerospan)
% Get the index in the original num array:
indexOfStartOfLongestRun = measurements(indexOfLongestRun).PixelIdxList(1)
You will see that indexOfLongestRun = 9, which is where that run starts at.
More Answers (0)
See Also
Categories
Find more on Polynomials 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!