permutation without replacement matrix
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Manoj
el 23 de Jun. de 2014
Comentada: James Tursa
el 26 de Nov. de 2019
I would like to find out the number of possibilities when drawing k balls from an urn with n balls: k=6; n=12
This is of the type variations (In compliance with the order) and without repetitions (replacement)
Therefore I need a matrix of the size=[665280*12] and it looks like this
[0 0 0 0 0 0 1 2 3 4 5 6]
The rows will always have 6 zeros in any order and the remaining will be filled by the numbers 1 to 6. The total possibilities are obtained by n!/(n-k)!
Please help me to get this matrix
Best Regards Manoj
3 comentarios
Respuesta aceptada
Jos (10584)
el 26 de Jun. de 2014
% a smaller example
k = 2 ;
n = 4 ;
v = perms(1:k) % all permutations of values 1:k
v = [zeros(size(v,1),1) v] % add a row of zeros
p = permpos(1:k, n) % my function!
% create permutations
c = arrayfun(@(x) reshape(v(x,p+1),size(p)),1:size(v,1),'un',0)
c = vertcat(c{:})
c = sortrows(c) % cleaner output
My function PERMPOS can be downloaded here:
5 comentarios
Más respuestas (1)
Gabriel Rodriguez
el 26 de Nov. de 2019
how to turn matrix without usin' the apostrophe, rot90, flipud, fliplr
1 comentario
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!