generating 2 bits sequence of binary data
18 views (last 30 days)
Show older comments
Ayesha Punjabi
on 20 Feb 2019
Commented: Walter Roberson
on 27 Feb 2019
tag_arr = randi(0:1,1,5);
is giving random 0 and 1
tag_arr = randi(0:1,1,5)
tag_arr =
0 0 0 1 1
I am trying to gain 2 bits data
that means tag_arr should be randomly show in the following manner
tag_arr =
00 10 01 10 01 10
i tried several ways of using randi syntax but its not working kindly help
3 Comments
Walter Roberson
on 27 Feb 2019
"binary characters" do not exist in MATLAB. Signed and unsigned integers exist in MATLAB; single precision and double precision floating point value exist in MATLAB; characters exist in MATLAB; logical values (that are mostly treated as being 0 and 1 for numeric purposes) exist in MATLAB. General binary does not exist in MATLAB. The closest MATLAB gets is the fixed-point datatype.
Accepted Answer
Walter Roberson
on 27 Feb 2019
Edited: Walter Roberson
on 27 Feb 2019
You cannot do that. MATLAB does not have a "binary" datatype that can display a bit pair without a space between the bits.
Your choices are:
- use decimal instead of binary. So 00 10 01 10 01 10 would be decimal zero ten one ten one ten and would display as 0 10 1 10 1 10 . The decimal values would have to be broken up again using mod() or similar if you wanted to do computation.
- use arrays of numbers. So 00 10 01 10 01 10 would be [0 0; 1 0; 0 1; 1 0; 0 1; 1 0] . This would be randi(0:1, 5, 2) . Nothing special would need to be done to use computation.
- Use character arrays. So 00 10 01 10 01 10 would be ['00'; '10'; '01'; '10'; '01'; '10']. This would be char(randi(0:1, 5, 2)+'0') . The character arrays would have to have '0' (character for digit 0) to be subtracted to do computation.
- Use character vectors. So 00 10 01 10 01 10 would be '00 10 01 10 01 10' with embedded spaces. This is a bit more of a nuisance to generate. The character vector would have to be transformed in order to do computation.
- Use decimal values internally and transform them for display. So 00 10 01 10 01 10 would be stored as decimal 0 2 1 2 1 2 and you would use a small function to display them in binary when you wanted to see them.
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!