Can I use unary coding to convert a vector of decimals into a binary matrix?

I am trying to convert a decimal vector into a matrix of binary numbers using unary coding. For example:
1 -> 1 0 0 0
2 -> 0 1 0 0
3 -> 0 0 1 0
4 -> 0 0 0 1
I'd like to do this using vector arithmetic, not looping over all of the rows.

1 Comment

There are multiple competing stands for unary coding. Which one are you following? How are you representing 0? How are you representing negative numbers? Do you need to represent fractions?

Sign in to comment.

More Answers (0)

Asked:

on 18 Mar 2013

Community Treasure Hunt

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

Start Hunting!