Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Data type conversion in matlab

  1. Jun 18, 2008 #1
    I'm writing a program in matlab. I have a matrix whose entries are all ones and zeros. I want to convert each row vector of the matrix into a binary number whose digits are the entries of the vector. So for example if an arbitrary row of the matrix was [1, 0, 1, 1], I would like to convert it into the binary number 1011. How would I go about doing that? My end goal is to convert that binary number into a base ten one, but I already know how to do that.
  2. jcsd
  3. Jun 19, 2008 #2
    Well, it could be done by using the following simple formula:

    where a_i are the elements of the vector and N is the dimension.
  4. Feb 7, 2011 #3
    In case you have numeric (double integer) valued matrix components, then you can use the following MATLAB conversion:


    then back to double integer you can convert using:
    C=bin2dec(B); % NB: You will loose however decimal points

    Hopefully that helps you.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Data type conversion in matlab
  1. R Type Conversion (Replies: 2)