フィルターのクリア

please help in this program. is to find the index of zeros which is in consecutive order which should more or equal to 5 time.

2 ビュー (過去 30 日間)
a=[0,0,0,0,0,0,0,0,9,8,5,6,0,0,0,0,0,0,3,4,6,8,0,0,9,8,4,0,0,7,8,9,5,0,0,0,0,0,8,9,0,5,8,7,0,0,0,0,0]; [x,y]=size(a);
for i=0:y i+1; k=1; l=0; n=i; count=0;
while (a==0)
count+1;
break;
n+1;
end
if(count>=5)
v([]);
for l=k:l<n
v(m)=l+1;
m+1;
end
end
count=1;
i=n;
end
for i=o:i<m
i+1;
fprintf('index of continous zero more than 5 or equal=%d',v(i));
end

採用された回答

Image Analyst
Image Analyst 2014 年 5 月 21 日
It's trivial if you have the Image Processing Toolbox:
a = [0,0,0,0,0,0,0,0,9,8,5,6,0,0,0,0,0,0,3,4,6,8,0,0,9,8,4,0,0,7,8,9,5,0,0,0,0,0,8,9,0,5,8,7,0,0,0,0,0];
% Measure lengths of all "0" regions.
measurements = regionprops(a == 0, 'Area', 'PixelIdxList');
% Get indexes of those regions that are >= 5 in length.
fiveLongRegions = find([measurements.Area] >= 5)
theIndexes = vertcat(measurements(fiveLongRegions).PixelIdxList)
% Get a logical output vector which is true if it's in a >=5 region.
output = false(1, length(a)); % Initialize
% Set elements = 1 if it's in a >=5 region.
output(theIndexes) = true

その他の回答 (1 件)

María
María 2014 年 5 月 21 日
編集済み: María 2014 年 5 月 21 日
I don't know if this is what you men:
a=[0,0,0,0,0,0,0,0,9,8,5,6,0,0,0,0,0,0,3,4,6,8,0,0,9,8,4,0,0,7,8,9,5,0,0,0,0,0,8,9,0,5,8,7,0,0,0,0,0]; [x,y]=size(a); cont=0; v=[];
for i=1:y
if a(i)==0
cont=cont+1;
else
if cont>=5
v=[v,i-cont]
end
cont=0;
end
end
if cont>=5
v=[v,i-cont]
end
for i=1:length(v)
fprintf('index of continous zero more than 5 or equal=%d',v(i)); end
  1 件のコメント
Y.L.K KHUMAN
Y.L.K KHUMAN 2014 年 5 月 21 日
it's for finding the index of zero's element, only those which are in consecutive order of greater than 5.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by