Skip to main content

Posts

Showing posts from May, 2016

Generating binary vectors in Matlab

More of a note to self than a blog post, but a really useful way to generate vectors of binary numbers in Matlab is the following dec2bin(Num,nBits)-'0' This generates a vector of "nBits" in length for number "Num". The '0' at the end converts it from a string into a vector for some reason. E.g. dec2bin(3,4)-'0' = [0 0 1 1] I found this out from Stack Overflow: http://stackoverflow.com/questions/5744576/convert-decimal-to-binary-vector