MATLAB: How to generate 200 random numbers between -1 and 1 (x-axis and y-axis), resulting in plot from x-axis -1 to 1 and y-axis -1 tot 1 filled with 200 blue diamond points

randrandnvector

I can't get the first generated random number to be drawn at x= -1. it always starts a 1 and has an interval of 1 until 200. I do not want that.
I want to create a vector x (containing 200 random values between -1 and 1).
x = -1 + randn(200)
subplot(1,2,1), plot (x,'bd')
axis([-1 1 -1 1]);

Best Answer

Two problems--
  1. x = -1 + randn(200) simply shifts mean of RNV from 0 to -1 leaving range alone about mean
  2. plot (x,'bd') plots the two columns against ordinal number 1:200 since is no 'x' argument supplied, only 'y'. Just naming a variable 'x' doesn't change meaning of positional arguments.
Try
x=2*rand(200,1)-1;
y=2*rand(200,1)-1;
plot(x,y,'bd')
for uniform PRVs; note that randn generates PR Normal Vs
Related Question