Generate a random signal in Matlab

4 visualizzazioni (ultimi 30 giorni)
Chase Murphy
Chase Murphy il 17 Ott 2019
Commentato: Steven Lord il 17 Ott 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?

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Random Number Generation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by