Applying mvnpdf to multiple points in an array

3 ビュー (過去 30 日間)
Eric
Eric 2018 年 10 月 20 日
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 Center および File ExchangePowertrain Blockset についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by