Generate random polynomials with MATLAB

2019-08-11 14:42发布

问题:

I want to generate random binary polynomials with parameters (n,m).

n is the number of polynomials to be generated and m is the number of elements of each polynomials.

At the same time I need it's polynomial to be unique. And I also need to exclude the result with all elements equal to zero.

For example for n=3 and m=3 I am looking for something like [1 0 1] [1 0 0] [1 1 1].

Is there any command in mat lab which I can use to have the above results?? I would also like to avoid the for loop if possible!!

EDIT: I found that the command unique(rand(n,m)>=0.5,'rows') will do the job. But this does not guarantee that the result [0 0 0] will be excluded

any ideas?

回答1:

Each of your polynoms could be interpreted as a binary number between 1 and 2^m-1.

%get a random subset of size n
X=randperm(2^m-1,n);
%convert it to a matrix
X=dec2bin(X)-'0';