How to generate binary vector ?
Show older comments
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 Comments
James Tursa
on 28 Mar 2019
There are many ways of doing this. Please give us more detail about your problem.
Walter Roberson
on 28 Mar 2019
Which deterministic algorithm do you want?
yousef Yousef
on 28 Mar 2019
Walter Roberson
on 28 Mar 2019
Edited: Walter Roberson
on 28 Mar 2019
oldstate = rng('twister', 54321); a = randi([0 1], 1, n); rng(oldstate);
yousef Yousef
on 28 Mar 2019
Walter Roberson
on 28 Mar 2019
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
on 28 Mar 2019
Walter Roberson
on 28 Mar 2019
a = zeros(1, n); a(1:2:end) = 1;
yousef Yousef
on 28 Mar 2019
yousef Yousef
on 28 Mar 2019
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!