I have, say, two probability variables: xval=[1 2] with probability xp=[0.5 0.5] and yval=[1 2] with probability yp=[0.75 0.25]
The probability table of these two, I can calculate using: [X,Y]=ndgrid(xp,yp); jpdf=X./Y; which gives me the joint probabilities with the values [1 2; 2 4].
I can calculate the values of the probabilities using: j=find(xp>0)'*find(yp>0);
But now I want to convert this, in as little code as possible, to an array which holds the combined probability values. i.e.: xyval=[1 2 3 4] with probability xyp=[0.375 0.5 0 0.125]
The 2nd term in xyp is constructed from 0.375+0.125, because there are two values of '2' in the probability table.
There are ways to do this which are unnecessarily long, but I'm looking for something in a few lines at most. Any idea's? Thanks, sim
Best Answer