這是我試圖找到大於或等於5的連續零的代碼。在Matlab中查找五個或更多個連續的零的運行
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
那麼優雅,耶! –
如果我們想要找到中間零索引而不是開始零索引,那麼該怎麼辦,即v = 4 16等 –
@FarazAhmad使用'v +(n + 1)/ 2'? –