Late, but as promised
I promised a matlab puzzle.
So I'm trying to get the probability of an event from a multinomial distribution. I currently have a function that takes in a vector x and returns the number of permutations of that many elements:
What I'd like to be able to do is accept a 2-d matrix, and have this function act on each row and return a column vector, without using any for loops. I can write factorial any of the following ways for a single value:
But again, those don't generalize so well. A factorial that generalizes to act on each element of an array would be spiffy.
Edit: The exact function I'm looking for exists in Matlab 7. In fact, the factorial() function in matlab 7 works exactly how I want it to. I'm using matlab 6.5. If anyone out there actually has matlab 7, and can open their factorial.m and tell me how it works, I'd be much obliged.
click
So I'm trying to get the probability of an event from a multinomial distribution. I currently have a function that takes in a vector x and returns the number of permutations of that many elements:
d = factorial(sum(x));
for y = x
d = d / factorial(y);
end
return dWhat I'd like to be able to do is accept a 2-d matrix, and have this function act on each row and return a column vector, without using any for loops. I can write factorial any of the following ways for a single value:
prod(1:x) prod(cumsum(ones(1, x)))
But again, those don't generalize so well. A factorial that generalizes to act on each element of an array would be spiffy.
Edit: The exact function I'm looking for exists in Matlab 7. In fact, the factorial() function in matlab 7 works exactly how I want it to. I'm using matlab 6.5. If anyone out there actually has matlab 7, and can open their factorial.m and tell me how it works, I'd be much obliged.
click

no subject