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,[])')+1out=a(idx)If you want to join themout=strjoin(a(idx),'') Related SolutionsMATLAB: Decoding DNA sequence into binary One way:s = 'TGACTCAGTCGTTCAATCTATGCC'; % Input DNA string[~,x] = ismember(s,'ATGC'); % Convert the ATGC into indexesc = {'00','01','10','11'}; % Numeric strings to convert the indexes intoresult = cell2mat(c(x)); % Convert the indexes into the numeric strings MATLAB: Conversion from binary to decimal First of all, it would bescale = bin2dec(item); %no quotes!Secondly, your bit values are probably values of 0 and 1, whereas bin2dec needs values of '0' and '1'item = char('0' + bits(i,:)); Related QuestionConverting a string of variables to numbersConvert an string stored in a cell to a numberArray: concatenate two columns of integers to one columHow to XOR two cells from the same cell arrayHow to convert .txt file data to a matrix formFind a series of consecutive numbers and change index of them
Best Answer