MATLAB: How to create binary matrix in matlab

binarydecimal

hello,
I'm wondering how to create a binary matrix in matlab
and how to convert a matrix from decimal to binary and from binary to decimal

Best Answer

For the First part of the question please refer to link here (@Walter Roberson's answer)
Second part, this is broad way to express-
Here I trying one example, please look
>> a=randi(5,5)
a =
1 5 2 5 4
5 5 4 4 4
3 3 2 2 5
5 2 4 4 5
4 1 1 2 2
>> binary=(a<3)
binary =
1 0 1 0 0
0 0 0 0 0
0 0 1 1 0
0 1 0 0 0
0 1 1 1 1
Here this is logical expression
If you are talking to decimal to binary, as processor do the computaion in binary values only, all decimal elements convert to binary as general. I hope you know the procedure.