MATLAB: How to generate a random decimal number between -1 and 1

random number generator

I'm trying to use rand below but it is giving me [ ].
rand([-1 1]);

Best Answer

The inputs to rand define its output size, not the output value range. Its range is fixed to 0..1, but you can adjust generate other values using some simple operations:
2*rand()-1
ans = -0.7192