generate odd and even numbers from randn function in simulink

조회 수: 4 (최근 30일)
Redhwan Mawari
Redhwan Mawari 2019년 8월 21일
댓글: John D'Errico 2019년 8월 23일
i need to generate odd and even numbers from a random binary array in simulink. Can someone help me with that. For example if i have a random arrary of binary numbers i.e. 0 1 1 1 0 0 1 and would like to split this array to even and odd index. So for even it would be: 1 1 0 and for odd: 0 1 0 1. I did it in matlab but could not do it in simulink. the matlab code is
data=randn(1,N)>=0; %Generating a uniformly distributed random 1s and 0s
oddData = data(1:2:end);
evenData = data(2:2:end);
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 8월 21일
It is not obvious why you are using randn()>=0 instead of rand() >= 0.5 ?
Redhwan Mawari
Redhwan Mawari 2019년 8월 21일
that will work as well. The issues is generating odd and even from the binary numbers.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 8월 21일
https://www.mathworks.com/help/dsp/ref/variableselector.html -- use twice, once to select row 1 (odd indices), once to select row 2 (even indices)
The above two require DSP.
If you have a fixed signal length then you could use https://www.mathworks.com/help/simulink/slref/selector.html listing all of the desired indices directly (I am not sure if you can use colon notation there.)
  댓글 수: 4
Walter Roberson
Walter Roberson 2019년 8월 21일
편집: Walter Roberson 2019년 8월 21일
After which you can use variableselector or https://www.mathworks.com/help/simulink/slref/selector.html to select the two different elements.
John D'Errico
John D'Errico 2019년 8월 23일
Moved from an answer to a comment:
"I’m trying to replicate the code below using simulink"
data=randn(1,N)>=0.5;
%Generating a uniformly distributed random 1s and 0s
odddata = data(1:2:end);
evenData = data(2:2:end);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Signal Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by