From: Mohammed Khalilia on 16 Feb 2010 11:39 I am trying to plot in 3D a dataset generated with a mean and covariance as follows: mean=[8 2] ; sigma=[4.1 0;0 2.8]; x = mvnrnd(mean,sigma,100) ; [X Y]=meshgrid(x(:,1),x(:,2)); Z = peaks(X,Y); surf(X,Y,Z); %or mesh(X,Y,Z) The 3D does not look correct, since it is a Gaussian dataset, I expect a nice bell shape, but what I get is more like a triangle. The elements in the Z matrix almost all are zeros. So I suspect that I generated the Z matrix incorrectly. I followed the examples from MATLAB documentation: [X,Y] = meshgrid(-2:.2:2, -2:.2:2); Z = X .* exp(-X.^2 - Y.^2); surf(X,Y,Z) Thanks for any suggestions.
From: Peter Perkins on 16 Feb 2010 14:19 On 2/16/2010 11:39 AM, Mohammed Khalilia wrote: > I am trying to plot in 3D a dataset generated with a mean and covariance > as follows: > mean=[8 2] ; > sigma=[4.1 0;0 2.8]; > x = mvnrnd(mean,sigma,100) ; > [X Y]=meshgrid(x(:,1),x(:,2)); > Z = peaks(X,Y); surf(X,Y,Z); %or mesh(X,Y,Z) > > The 3D does not look correct, since it is a Gaussian dataset, I expect a > nice bell shape, but what I get is more like a triangle. The elements in > the Z matrix almost all are zeros. So I suspect that I generated the Z > matrix incorrectly. If you're expecting to see something like the density of a bivariate normal distribution, then I'd have to agree. How about this: x = mvnrnd(mean,sigma,10000); hist3(x) or the example on this page in the documentation: <http://www.mathworks.com/access/helpdesk/help/toolbox/stats/brn2ivz-89.html> Hope this helps.
|
Pages: 1 Prev: How to run multiple m-files in a single instance of matlab? Next: Read malformed text file |