How to Convert Matrix Rows to Binary Numbers in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter xentity1x
  • Start date Start date
  • Tags Tags
    Data Matlab Type
Click For Summary
SUMMARY

This discussion focuses on converting matrix rows of binary values into binary numbers using MATLAB. The user seeks to transform a row vector, such as [1, 0, 1, 1], into its binary representation, 1011. The solution involves using the MATLAB function dec2bin to convert the matrix and bin2dec to convert the binary string back to a decimal integer. The provided formula for conversion is nbr = ∑(a_i * 10^(N-i)), where a_i are the matrix elements and N is the row dimension.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of binary number representation
  • Knowledge of matrix operations in MATLAB
  • Basic concepts of number base conversion
NEXT STEPS
  • Explore MATLAB's dec2bin function for binary conversion
  • Learn about MATLAB's bin2dec function for decimal conversion
  • Research matrix manipulation techniques in MATLAB
  • Study binary arithmetic and its applications in programming
USEFUL FOR

MATLAB programmers, data analysts, and anyone interested in binary data manipulation and conversion techniques.

xentity1x
Messages
9
Reaction score
0
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.
 
Physics news on Phys.org
Well, it could be done by using the following simple formula:
[tex]nbr=\sum_{i=1}^{N}a_{i}10^{N-i}[/tex]

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

B=dec2bin(A);

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

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 2 ·
Replies
2
Views
5K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K