Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create matrix with random binary element in matlab

Tags:

matlab

I want to create a matrix in matlab with 500 cell (50 row,10 column ), How I can create and initialize it by random binary digits? I want some thing like this in 50*10 scale as sample 3*4

0 1 1 1
0 0 0 0
1 1 1 1

and after it, how can get decimal equation of any row ? like row 1 is equal 7 in decimal

like image 295
Yuseferi Avatar asked Oct 14 '12 06:10

Yuseferi


2 Answers

Why not use randi to generate random integers?

A = randi([0 1], 50, 10);

and to convert a binary row to a number - as in the previous answers:

bin2dec(num2str(A(n,:)))
like image 116
angainor Avatar answered Oct 02 '22 13:10

angainor


Another option:

 A=round(rand(50,10));

The decimal eq of the n-th row is given by:

 bin2dec(num2str(A(n,:)))
like image 23
bla Avatar answered Oct 02 '22 12:10

bla