r=rand(1,5);help find;temp=find(r<0.5);r(temp)=0;https://bookstack.bookcodes.cn
a=rand(1,5)a(find(a<0.5))=0 只要这两行代码即可