How to generate binary vector ?

How to generate a vector of unique ( deterministic not random ) sequence of bits ?. I want a binary vector to use in many different codes for comparison

10 comentarios

James Tursa
James Tursa el 28 de Mzo. de 2019
There are many ways of doing this. Please give us more detail about your problem.
Walter Roberson
Walter Roberson el 28 de Mzo. de 2019
Which deterministic algorithm do you want?
yousef Yousef
yousef Yousef el 28 de Mzo. de 2019
I want to generate a unique sequence zeros and ones. The length of the vector is 100 for example. I want to do it using one or two commands. Every time I run it , it gives the same sequence.
Example a=[ 1 0 1 0 1 0 1 0.......] with length n=100.
Thanks
Walter Roberson
Walter Roberson el 28 de Mzo. de 2019
Editada: Walter Roberson el 28 de Mzo. de 2019
oldstate = rng('twister', 54321); a = randi([0 1], 1, n); rng(oldstate);
yousef Yousef
yousef Yousef el 28 de Mzo. de 2019
This line is not working.oldstate = rng('twister', 54321);
its giving me :
Error using rng (line 125)
First input must be a nonnegative integer seed less than 2^32, 'shuffle', 'default', or generator settings captured previously
using S = RNG.
oldstate = rng(65432, 'twister'); a = randi([0 1], 1, n); rng(oldstate);
I choose an initial seed that happens to give exactly 50 1's and 50 0's for n = 100.
yousef Yousef
yousef Yousef el 28 de Mzo. de 2019
Thanks for your help. I tried many times. Each time, it gives me the same sequence. Thats exactly what Iwant. One question if I want the sequence like [1 0 1 0 1 0 1 0 .....] is this possible?
Thanks
a = zeros(1, n); a(1:2:end) = 1;
yousef Yousef
yousef Yousef el 28 de Mzo. de 2019
Perfect. Thanks a lot
yousef Yousef
yousef Yousef el 28 de Mzo. de 2019
Last questions, what about if I want it as a train of pulses [1 0 1 0 1 0....]
Thanks

Iniciar sesión para comentar.

 Respuesta aceptada

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 28 de Mzo. de 2019

Comentada:

el 28 de Mzo. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by