MATLAB: How to write function to generate gaussian distribution of normal numbers with specified mean, variance and number of values

gaussianMATLABrandom numbersvariance

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]
end
x = x(idx);
x = x(1:nvals); % Extract numbers
end

Best Answer

you must return something from your function:
function x = distribution(va, mu, ul, ll, nvals)