Error when trying to plot 3D Joint PDF

1 回表示 (過去 30 日間)
Kaleem Graham
Kaleem Graham 2018 年 12 月 11 日
I'm suppose to plot the 3D Joint PDF of these two functions and compare it to the 3D Joint PDF of gaussian normal distribution, so I mulitplied them together but when I try to plot them I'm getting the (Z must be a matrix, not a scalar or vector error).
Question:
Question.png
Code:
>> mu = 0;sigma = 1; %mean = 0, variance = 1
>> L = 100000; %length of random vector
>> x1 = rand(L,1); %x1 uniformly distributed U(0,1)
>> x2 = rand(L,1); %x2 uniformly distributed U(0,1)
>> w1 = sqrt(-2*log(x1)).*cos(2*pi*x2); %w1 pdf declared
>> w2 = sqrt(-2*log(x1)).*sin(2*pi*x2); %w2 pdf declared
>> w = w1.*w2; %joint pdf declared
>> X = -10:0.1:10;
>> Y = X;
>> gaussNormal = pdf('Normal',X,mu,sigma); %declare gaussian normal pdf
>> [x,y] = meshgrid[X,Y];
>> mesh(x,y,w);
Error using mesh (line 71)
Z must be a matrix, not a scalar or vector.

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by