counting number of repeated elements

2 ビュー (過去 30 日間)
Masih Alavy
Masih Alavy 2017 年 7 月 31 日
コメント済み: Masih Alavy 2017 年 7 月 31 日
Hello All,
I have a large array with size (1224477x1 double). There are only 1s and 0s in this array. What I want to do is the following: First, I want to count the number of times 0s are repeated consecutively. If this number exceeds 360, I want to isolate that section of the array and perform some other calculations on them. And then move on to the other section which has more than 360 consecutive 0s. How do I do that? Thanks

採用された回答

Image Analyst
Image Analyst 2017 年 7 月 31 日
You can use regionprops() to get the length, then do something on each set of indexes where the length exceeds 360. If you have the Image Processing Toolbox, here's a start
% Find zeros, convert to binary, then label each region:
[labeledRegions, numRegions] = bwlabel(doubleVector == 0);
% Measure lengths of each region, and get indexes of each region.
props = regionprops(labeledRegions, 'Area', 'PixelIdxList');
% Loop over all regions, looking for regions that are 360 elements or longer.
for k = 1 : numRegions
% See if this stretch of zeros is 360 or longer.
if props(k).Area >= 360
% This stretch of zeros is 360 or longer.
theseIndexes = props(k).PixelIdxList;
% Now do something with these indexes.
end
end
  1 件のコメント
Masih Alavy
Masih Alavy 2017 年 7 月 31 日
This works beautifully. Thanks.

サインインしてコメントする。

その他の回答 (1 件)

the cyclist
the cyclist 2017 年 7 月 31 日
The first thing I would do is download the very handy RunLength code from the File Exchange. That will give you a good start.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by