MATLAB: How to generate random numbers in a range with decimal steps random number generator Hi How can I generate a random decimal number inbetween a range of 0 and 0.5 (i.e. 0, 0.1, 0.2, 0.3, 0.4, 0.5)? Best Answer >> V = 0:0.1:0.5; % define the numbers>> V(randi([1,numel(V)]))ans = 0.4>> V(randi([1,numel(V)]))ans = 0.2>> V(randi([1,numel(V)]))ans = 0.5>> V(randi([1,numel(V)])) Related SolutionsMATLAB: Random numbers help randdoc rand MATLAB: How to generate a vector of uniformly distributed numbers around 1 >> 2*rand(1,10)ans = 1.324304 0.866104 0.570201 1.248882 0.425728 1.720565 0.022849 1.249922 1.828464 1.977158Of course you could generalize this for a particular offset and range:off = 0.4;wid = 1.5off+wid*rand(...) Related QuestionHow to increase GUI slider stepsHow to create a random matrix that contains only of 0’s, 0.5’s and 1’sHow to vectorize a nested for loop with different sized steps
Best Answer