Generate random polynomials with MATLAB

情到浓时终转凉″ 提交于 2019-12-11 12:07:44

问题


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';


来源:https://stackoverflow.com/questions/31356496/generate-random-polynomials-with-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!