histogram of Bivariate Normal distribution plot
9 次查看(过去 30 天)
显示 更早的评论
I have values from a monte carlo simulation. now i am supposed to plot the results using a bivariate gaussian.
Since it is experimental data on a specific topic, i was given the empirical formula of the PDF(x,y):
and this is the plot I should get( obviously it will be different depending on my data):
I don't understand how to implement the plot
This is the part of the code where I calculate STD, means:
N=1000
x=detriti_coord(:,1); %along-track direction Gaussian
y=detriti_coord(:,2); %cross-track direction Gaussian
mu_x=mean(x);
mu_y=mean(y);
sigma_x= sqrt(1/N*sum((x-mu_x).^2))
sigma_y= sqrt(1/N*sum((y-mu_y).^2))
Delta_x= x-mu_x;
Delta_y= y-mu_y;
rho_xy= sum(Delta_x.*Delta_y)/(N*sigma_x*sigma_y);
0 个评论
回答(1 个)
Yash
2023-11-16
Hi Giovanni,
I understand that you are facing issues while making a 3 dimensional histogram of a PDF function.
Since you have clearly mentioned that you are facing issues in the implementation of the plot, I am assuming that your calculations are correct. From the problem statement, it seems that you want to plot the histograms of x and y values from the experimental data.
To achieve this, you can use the "hist3" function. You can refer the to the documentation for "hist3"at the following link: https://www.mathworks.com/help/stats/hist3.html.
If you want to plot the rho_xy as well with the histogram, you can use the "surf" function. You can refer the to the documentation for "surf" at the following link: https://www.mathworks.com/help/matlab/ref/surf.html
Note that to show both the plots in the same axes, you need to use "hold on".
I am using random values to show an example:
x = randi(10, 100, 1); %100*1 matrix of random doubles ranging from 0 to 10
y = randi(10, 100, 1);
hist3([x y]);
hold on
arraySize = 100;
sigma = 50;
x1 = linspace(0,10,arraySize); %100 points between 0 to 10
[X,Y] = meshgrid(x1,x1); %setting up for the x and y axis for the surf plot
z = fspecial("gaussian", arraySize, sigma); % gaussian distribution
z = z*(3/max(z,[],'all')); % scaling from 0 to 3
surf(X,Y,z);
hold off
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!