How to generate a joint probability matrix from a data matrix
Mostrar comentarios más antiguos
Suppose I have a data matrix
Sample# X Y
1 1 1
2 1 2
3 1 1
Then I want to generate a joint prob matrix
X Y Prob
1 1 0.67
1 2 0.33
Please advise.
Respuesta aceptada
Más respuestas (1)
Roger Stafford
el 17 de Mzo. de 2018
Call the data matrix D. Then the two columns of D(:,2:3) are X and Y.
XY = sortrows(D(:,2:3));
F = find( [true,any(XY(1:end-1,:)~=XY(2:end,:),2),true] );
J = [XY(F(1:end-1),2:3),diff(F)/(F(end)-1)]; % <-- Joint probabilities in column 3
Columns 1 and 2 of J will contain unique X Y pairs.
Categorías
Más información sobre Particle & Nuclear Physics en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!