I am using MATLAB R2020a Psychtoolbox on Mac OS. I found the following code here to generate a gaussian distribution of random numbers and used it to write a function to specify the mean, variance, upper and lower limits and number of values, however it doesn't generate the numbers.
function distribution(va, mu, ul, ll, nvals)multiplier=10;x = mu + randn(multiplier*nvals,1)*sqrt(va); % Generate sufficient random numbers
idx = (ll <= x) & (x <= ul); % Extract the value in the given range [min max]
while sum(idx)<nvals multiplier=multiplier+1; x = mu + randn(multiplier*nvals,1)*sqrt(va); % Generate sufficient random numbers idx = (ll <= x) & (x <= ul); % Extract the value in the given range [min max]endx = x(idx);x = x(1:nvals); % Extract numbers
end
Best Answer