In the following code I get matrix 'a' with repeated columns. How to generate it without repetition?

1 次查看(过去 30 天)
if true
k=3;
n=5;
m=(2*k)-2;
n1=k-1;
N=(factorial(m))/(factorial(n1)*factorial(n1));
o = ones(k-1,1) ;
z = zeros(k-1,1) ;
a1 = [o ; z];
n2=1;
for i=1:N
a(:,n2)= randsample([o ; z],m)
n2=n2+1;
end
end

采纳的回答

KSSV
KSSV 2018-1-5
k=3;
n=5;
m=(2*k)-2;
n1=k-1;
N=(factorial(m))/(factorial(n1)*factorial(n1));
o = ones(k-1,1) ;
z = zeros(k-1,1) ;
a1 = [o ; z];
v = a1' ;
C = unique(perms(v),'rows') ;
  1 个评论
PLACEIUS NISHIGA G
编辑:PLACEIUS NISHIGA G 2018-1-5
Thank you sir. It helped us. But the elements in each column is the same every time I execute it. The elements in each column need to be randomly generated for every execution without repetition with other columns.
if true
% code
k=3;
n=5;
m=(2*k)-2;
n1=k-1;
N=(factorial(m))/(factorial(n1)*factorial(n1));
o = ones(k-1,1) ;
z = zeros(k-1,1) ;
a1 = [o ; z];
v = a1' ;
C = unique(perms(v),'rows') ;
C=C'
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by