gpt4 book ai didi

arrays - 在 Matlab 中查找五个或更多连续零的序列

转载 作者:行者123 更新时间:2023-12-02 08:10:27 25 4
gpt4 key购买 nike

这是我试图找到顺序为 5 或更多的连续零的代码。

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

最佳答案

如果您想查找 n 或更多零的运行的起始索引:

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

在您的示例中,这给出了

v =
1 13 34 45

关于arrays - 在 Matlab 中查找五个或更多连续零的序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23782051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com