Generate a random signal in Matlab

2 次查看(过去 30 天)
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?

采纳的回答

Daniel M
Daniel M 2019-10-17
y = (rand(10000,1) > 0.5)*2 -1;
  8 个评论
Walter Roberson
Walter Roberson 2019-10-17
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
Steven Lord 2019-10-17
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by