找到连续五年以上的零在Matlab运行 [英] Find a run of five or more consecutive zeros in Matlab
本文介绍了找到连续五年以上的零在Matlab运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是code,我曾试图找到连续的零这是在5或以上的订单。
<$p$p><$c$c>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] =尺寸(一);对于i = 0:YI + 1;
K = 1;
L = 0;
N =;
计数= 0;而(A == 0)
数+ 1;
打破;
N + 1;
结束
如果(计数&GT; = 5)
V([]);
对于L = K:L&LT; N
V(米)= L + 1;
m + 1个;
结束
结束
数= 1;
I = N;
结束
对于i = O:I&LT,M
I + 1;fprintf中('的连续零指数大于5或等于=%d个'V(I));结束
解决方案
如果你想找到的运行的起始指数 N
或多个零:
V =找到(CONV(双(一== 0),一(1,N),有效)== N); //%找到N个零,
V =([真差异(ⅴ)将N]); //%相似删除指数,说明N + 1,N + 2 ...零
在你的榜样,这给
V =
1 13 34 45
This is the code that I had tried to find the consecutive zero which are in the order of 5 or more.
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
解决方案
If you want to find the starting indices of runs of n
or more zeros:
v = find(conv(double(a==0),ones(1,n),'valid')==n); %// find n zeros
v = v([true diff(v)>n]); %// remove similar indices, indicating n+1, n+2... zeros
In your example, this gives
v =
1 13 34 45
这篇关于找到连续五年以上的零在Matlab运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文