Converting between decimal and unary in Matlab

Decimal to unary:

[1:4]'==3   % returns [0 0 1 0 ]

Unary to decimal:

max([0 0 1 0] .* (1:4))   % returns 3