use matlab code to draw the joint PMF and CDF

52 vues (au cours des 30 derniers jours)
Ee
Ee le 27 Nov 2021
Modifié(e) : Chunru le 28 Nov 2021
Hi, I am here confused about how to use 3D plot to draw the PMF (Probability Mass function) and CDF(Cumulative Distribution Function) based on x y two random variables. (The PMF I can draw it on paper but have no idea how to generate a code). Appreciate for the help
I tried the code below but it did not generate the graph what it supposed to be.
plot3([0 0 0],[0 0 0],[0 0 0.25])
hold on
plot3([1 0 0],[0 0 0],[0 0 0.125])
plot3(1, 0, 2)
hold on
plot3([0 0 0],[0 1 0],[0 0 0.5])
hold on
xlabel('X')
ylabel('Y')
zlabel('Probability')
grid on

Réponses (1)

Chunru
Chunru le 28 Nov 2021
Modifié(e) : Chunru le 28 Nov 2021
[x, y] = meshgrid([0 1], [0 1])
x = 2×2
0 1 0 1
y = 2×2
0 0 1 1
z = [0.25 0.5; 0.125 0.125]';
stem3(x, y, z)
xlabel('x');
ylabel('y');
zlabel('p')

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by