List of all Binomial permutations with a certain number of events
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello there,
I am trying to do something very simple I think and have come across this problem I cannot solve. I am not proficient with matlab.
All I want to do is to find all the possible permutation of tossing a coin 8 times where we ONLY have 4 heads and 4 tails. All of the possible combinations for only this scenario, the order does not matter.
so something like
1) H H H H T T T T
2) H H T T H H T T
3) H T T H H T H T
and so on....
0 Kommentare
Antworten (1)
Torsten
am 25 Nov. 2022
Bearbeitet: Torsten
am 25 Nov. 2022
n = 8;
A = dec2bin(0:2^n-1)-'0'
A4 = A(sum(A,2) == 4,:)
8*7*6*5/(4*3*2*1)
% more general
Ai = arrayfun(@(i)A(sum(A,2) == i,:),0:n,'UniformOutput',0)
sum(arrayfun(@(i)size(Ai{i},1),1:n+1))
2 Kommentare
Torsten
am 28 Nov. 2022
Yes.
The code after the comment
% more general
lists the combinations with 0,1,2,3,4,...,8 heads in a row separately.
The total number of combinations is 2^8, and this comes out to be true after the splitting of the possible outcomes.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!