Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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

Respuesta aceptada

KSSV
KSSV el 5 de En. de 2018
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 comentario
PLACEIUS NISHIGA G
PLACEIUS NISHIGA G el 5 de En. de 2018
Editada: PLACEIUS NISHIGA G el 5 de En. de 2018
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by