Generate a random signal in Matlab
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Chase Murphy
el 17 de Oct. de 2019
Comentada: Steven Lord
el 17 de Oct. de 2019
I need to generate a transmit signal of 10,000 random bits in MATLAB with values of -1 or +1, with both having a equal probabilty of occuring and then verify the probability.
I am using y=randi([-1 1],10000)
But I keep getting 0's and do not know how to take them out and am unsure if my function is even correct.
I tried verifying the probabilty by doing 2 different matrices and adding them together and should be equal to 0, but bc i have zeros this did not work.
Any suggestions?
0 comentarios
Respuesta aceptada
Daniel M
el 17 de Oct. de 2019
y = (rand(10000,1) > 0.5)*2 -1;
8 comentarios
Walter Roberson
el 17 de Oct. de 2019
p = sum(y==1)/numel(y);
for vector y that can be abbreviated to
p = mean(y==1)
for non-vector toss in a (:) after the y or use mean2() instead of mean()
Steven Lord
el 17 de Oct. de 2019
for non-vector toss in a (:) after the y or use mean2() instead of mean()
You can specify 'all' as the dimension input to mean if you're using release R2018b or newer of MATLAB.
>> A = magic(5);
>> mean(A, 'all')
ans =
13
>> mean(A(:))
ans =
13
>> mean(A)
ans =
13 13 13 13 13
Más respuestas (0)
Ver también
Categorías
Más información sobre Random Number Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!