MATLAB: Binary string to character conversion

binary string character conversion

How can i assign 00 to -3d, 01 to -d, 11 to +d, 10 to +3d if i have a binary string x = char('0' + (rand(1, 1000) < 0.5))?

Best Answer

x = char('0' + (rand(1, 1000) < 0.5))
a={'-3d' '-d' '+d' '+3d'}
idx=bin2dec(reshape(x,2,[])')+1
out=a(idx)
If you want to join them
out=strjoin(a(idx),'')