MATLAB Answers


generate odd and even numbers from randn function in simulink

Asked by Redhwan Mawari on 21 Aug 2019
Latest activity Commented on by John D'Errico
on 23 Aug 2019 at 15:43
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);


It is not obvious why you are using randn()>=0 instead of rand() >= 0.5 ?
that will work as well. The issues is generating odd and even from the binary numbers.

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 21 Aug 2019 -- 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 listing all of the desired indices directly (I am not sure if you can use colon notation there.)


Show 1 older comment
Which approach did you use?
Is your input a vector, and each time you want to take odd/even elements of the vector?
Or is your input a scalar signal, and you want to direct alternate bits different ways? Is it perhaps a Serial to Parallel convertor?
After which you can use variableselector or to select the two different elements.
Moved from an answer to a comment:
"I’m trying to replicate the code below using simulink"
%Generating a uniformly distributed random 1s and 0s
odddata = data(1:2:end);
evenData = data(2:2:end);

Sign in to comment.