Error when trying to plot 3D Joint PDF
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:
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.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:
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. 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:
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. mesh error pdf joint gaussian normal uniform distribution MATLAB Answers — New Questions