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

채택된 답변

Image Analyst
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
Monika  Kok
Monika Kok 2016년 4월 24일
yeah i understood from the earlier answer that what was longest zero span...but i need to also know that from which location this zero span is starting.
thanks monica
Image Analyst
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 CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by