detecting 6 ones in a vector
古いコメントを表示
i need a code to detect 6 consecutive ones in a vector and their places in the vector
3 件のコメント
jgg
2015 年 12 月 23 日
Image Analyst
2015 年 12 月 23 日
What if there are 10 ones in a row? You could fit 6 in there in a bunch of places. Would you want the only starting index of the run of 10 elements? Would you want all elements that are part of the 10? Or do you just want the 5 starting indices of where a segment of 6 could fit? You need to clarify because these would be three different algorithms.
shimaa ali
2015 年 12 月 23 日
採用された回答
その他の回答 (1 件)
Andrei Bobrov
2015 年 12 月 23 日
編集済み: Andrei Bobrov
2015 年 12 月 23 日
b = A == 1; % A - your array
t = [true;diff(b)~=0];
n = find(t);
p = [n,diff([n;numel(A)+1])];
out1 = p(A(n)==1,:);
out = out1(out1(:,2)==6,:);
or with Image Processing Toolbox
c = regionprops(A(:) == 1,'BoundingBox');
k = cat(1,c.BoundingBox);
out = ceil(k(k(:,4)==6,[2,4]));
カテゴリ
ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!