+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Newbie level 1
    Points: 100, Level: 1

    Join Date
    Dec 2016
    Posts
    1
    Helped
    0 / 0
    Points
    100
    Level
    1

    merging two coloumns of a matrix into one vector using matlab

    I was using matlab to convert a decimal numbers into binary using de2bi() function
    the problem is that de2bi returns the binary value into a matrix and i want it to be in a vector form
    inorder to be able to plot the binary values
    e.g
    de2bi(7) = 1 1 1
    i want it to be
    de2bi(7) = 111

    is there any method to help me

    •   Alt10th May 2017, 12:36

      advertising

        
       

  2. #2
    Newbie level 6
    Points: 112, Level: 1

    Join Date
    May 2017
    Posts
    11
    Helped
    6 / 6
    Points
    112
    Level
    1

    Re: merging two coloumns of a matrix into one vector using matlab

    "Plot the binary values"
    Do you mean you actually want the number 111 - one hundred and eleven?
    That seems a little nonsensical... But if you wish...
    Code:
    sum(de2bi(7).*10.^(2:-1:0))
    (only works for 3 digit binary numbers, but the change for arbitrary numbers should be obvious)
    If you want it in the form of a string, for printing, you could do:
    Code:
    char(de2bi(7) + '0')
    I believe this last line is equivalent to using dec2bin instead.


    1 members found this post helpful.

    •   Alt31st May 2017, 01:01

      advertising

        
       

  3. #3
    Member level 1
    Points: 640, Level: 5

    Join Date
    May 2015
    Posts
    37
    Helped
    0 / 0
    Points
    640
    Level
    5

    Re: merging two coloumns of a matrix into one vector using matlab

    In simple you can use this command dec2bin(x,n). For example
    Code:
    dec2bin(7,3)



--[[ ]]--