MATLAB: How to find a combination like this

combinatorics

I am wondering is there a way where I could use a matrix in combinatorics such as
nchoosek(4,1:4) where it calcluates 4choose1, 4choose2,… 4choose4 ?
Is thie possible in Matlab?

Best Answer

N = 4;
temp = factorial(0:N);
temp(end) ./ (temp .* fliplr(temp))
This would be 4C0, 4C1, 4C2, 4C3, 4C4, so you could index into the result to get the subset you need.