Creation of binary coded image from a matrix
Hi
I am looking for a fast code to do the following:
get a matrix with elements between 0 and 15
create a new matrix, double the size (both rows and columns)
for each element in the first matrix, set the binary representation of this element in the new matrix, in a 2×2 way.
first example
for a 1×1 input matrix:
A =
7
The result will be:
B =
0 1
1 1
Second example
for a 2×2 input matrix:
A =
0 2
1 3
The result will be:
B =
0 0 0 0
0 0 1 0
0 0 0 0
0 1 1 1
=
Currently, I do this with a slow for loop.
I would greatly apreciate your help.
DrorHi
I am looking for a fast code to do the following:
get a matrix with elements between 0 and 15
create a new matrix, double the size (both rows and columns)
for each element in the first matrix, set the binary representation of this element in the new matrix, in a 2×2 way.
first example
for a 1×1 input matrix:
A =
7
The result will be:
B =
0 1
1 1
Second example
for a 2×2 input matrix:
A =
0 2
1 3
The result will be:
B =
0 0 0 0
0 0 1 0
0 0 0 0
0 1 1 1
=
Currently, I do this with a slow for loop.
I would greatly apreciate your help.
Dror Hi
I am looking for a fast code to do the following:
get a matrix with elements between 0 and 15
create a new matrix, double the size (both rows and columns)
for each element in the first matrix, set the binary representation of this element in the new matrix, in a 2×2 way.
first example
for a 1×1 input matrix:
A =
7
The result will be:
B =
0 1
1 1
Second example
for a 2×2 input matrix:
A =
0 2
1 3
The result will be:
B =
0 0 0 0
0 0 1 0
0 0 0 0
0 1 1 1
=
Currently, I do this with a slow for loop.
I would greatly apreciate your help.
Dror matrix, binary MATLAB Answers — New Questions