回 帖 发 新 帖 刷新版面

主题:关于编程~~~~求助

wb=random('Weibull',7.5,2,1000,1);随机生成服从weibull分布的1000个数。
for n=1:length(wb); 
if wb(n)>=0&wb(n)<=1              1000个数中取出大于0而小于1的数并计算他们在1000个数
b(n)=wb(n);                       中出现的频率
else b(n)=0;
end
end
f1=nnz(b)/1000

问题是我想继续取出大于1而小于2的数并计算他们在1000个出现的频率怎么继续???
我老是出现错误。。。哪个大侠告诉下。。。

回复列表 (共2个回复)

沙发

for n=1:length(wb);
if wb(n)>=1&wb(n)<=2
b(n)=wb(n); 
else b(n)=0;
end
end
f2=nnz(b)/1000
for n=1:length(wb);
if wb(n)>=2&wb(n)<=3
b(n)=wb(n); 
else b(n)=0;
end
end
f3=nnz(b)/1000
上面是我自己编的。。请问哪个大侠能告诉怎么简化这个程序啊。。我觉得太麻烦了

板凳

wb=random('Weibull',7.5,2,1000,1);
>> n=length(find((wb>1)&(wb<2)))
n =
    59

我来回复

您尚未登录,请登录后再回复。点此登录或注册