how to determine starting location of longest zero pan in a column
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2016-4-24
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 个评论
Image Analyst
2016-4-24
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!