简体   繁体   中英

Matlab Binary Plot for Magnitude Representing the Whole 8 Bits

I am trying to achieve a magnitude binary plot, where y shows the binary magnitude for the 8 bits. Others have addressed this question through plotting individual bits, but the goal to show the whole 8 bits, represented as one number (ie 00000001 = 1), magnitude in binary form on the plot.

Here is the code:

     % Magnitude
     binMag = [00000001; 00000010; 00000100] 
% binary string representation of decimal 1, 2, 3
    % Tried to convert bin to a double
    binTodouble = str2double(binMag);
    figure;
    stairs(binTodouble)

Overall, my goal is to have a plot like the one below showing magnitude in binary. 在此处输入图片说明

Taking the idea from Cris Luengo into account, you'll get the following short script. I just wanted to add how to specifically set the xticklabel and yticklabel as you wanted it to have in your plot.

% Binary values
bValues = { '00000000', 
            '00000001', 
            '00000010', 
            '00000011', 
            '00000100', 
            '00000101' };

% Double values
dValues = bin2dec(bValues);

% Output
figure(1);
stairs(dValues, dValues);
set(gca, 'xtick', dValues, 'xticklabel', dValues);
set(gca, 'ytick', dValues, 'yticklabel', bValues);

楼梯图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM