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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!