lundi 10 septembre 2018

Substitute values in an array with a random number if value>1

I have an array (1000 x 8) of values generated from a log-normal distribution representing the % die-off of bacteria on a surface after an hour. The problem is that some values are larger than 100% so I'd like to replace them with a random value between 0 and 1.

dieOff=zeros(1000,8); %make empty 1000X8 array
m = 0.9; % 90% die-off
v = 0.01;% std from experiment


mu = log((m^2)/sqrt(v+m^2)); %conver to lognorm
sigma = sqrt(log(v/(m^2)+1));

dieOff=lognrnd(mu,sigma,n,k);% generate values

dieOff(dieOff>1)=rand(); %replace with random

But it looks like rand() only produces 1 value and replaces all the values that are > 1 with that same value which is not what I'd like. How can I fix this in a neat format?

histogram(dieOff) 

enter image description here




Aucun commentaire:

Enregistrer un commentaire