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

José-Luis
José-Luis 2014년 6월 23일
What have you tried so far?
Manoj
Manoj 2014년 6월 24일
Well I tried using the perms functions and even nchoosek , but nothing seems to work. I am not sure how to approach the problem
Manoj
Manoj 2014년 6월 24일
편집: Manoj 2014년 6월 24일
if true
% code
end
a = [0 0 0 0 0 1 2 3 4 5 ];
c =combinator((length(a)),10,'p'); % Take 10 at a time.
d = unique(a(c),'rows');
This is where I have arrived at. I found this combinator function that I could use. The problem is it gives me the variable d which is required by me. It is right for 10 values, but I want for 12 values and currently it says out of memory. Anyway to get the solution from here ?

댓글을 달려면 로그인하십시오.

 채택된 답변

Jos (10584)
Jos (10584) 2014년 6월 26일

2 개 추천

% 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

Manoj
Manoj 2014년 6월 26일
This is exactly what I was looking for , it is working for the huge matrix I wanted as well. Thank you so much Jos, really appreciate it :)
Manoj
Manoj 2014년 6월 26일
Thank you so much José-Luis as well, helped me to understand the problem much better
Jos (10584)
Jos (10584) 2014년 6월 26일
You're welcome. So which answer did you accept?
Manoj
Manoj 2014년 6월 26일
편집: Manoj 2014년 6월 26일
I am going to use your answer since it is exactly what I wanted , but I had already accepted José-Luis's answer so I am not sure how to accept your answer now. That is why I gave you 1 vote :) I am not sure how to change this
José-Luis
José-Luis 2014년 6월 26일
편집: José-Luis 2014년 6월 26일
I am going to delete my answer so you can accept Jos'. Don't know if it it will work since I have never done that.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Gabriel Rodriguez
Gabriel Rodriguez 2019년 11월 26일

0 개 추천

how to turn matrix without usin' the apostrophe, rot90, flipud, fliplr

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2014년 6월 23일

댓글:

2019년 11월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by