Applying mvnpdf to multiple points in an array

1 次查看(过去 30 天)
I have a 100-by-150 grid (unit spacing) and would like to generate bivariate normal distributions around some, but not all, of the points. Is there a way to do this with mvnpdf in one step? Or, do I need to use a for loop to do the computation for each grid point in turn, summing the values to produce the final array, as in the following snippet? =================================================== x = 0:1:9; y = 0:1:14; [X,Y] = meshgrid(y,x); mu = [5 7; 3 2; 2 10]; % work with 3 grid points Sigma = zeros(2,2,length(x)); % Need cov. matrix for each row in x for s = 1:size(X,1) % Allow for point-specific covariance matrix Sigma(:,:,s) = [.25 .3; .3 1]; % Same cov. matrix at all points end F = zeros(size(X)); F_total = zeros(size(X)); for i = 1:size(mu,1) F = mvnpdf([X(:) Y(:)],mu(i,:),Sigma(:,:,i)); F = reshape(F,length(x),length(y)); F_total = F_total + F; end surf(y,x,F_total); colormap('jet'); caxis([min(F(:))-.5*range(F(:)),max(F(:))]); xlabel('y'); ylabel('x'); zlabel('Probability Density'); shg; ===================================================
Thanks in advance for your help!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by