필터 지우기
필터 지우기

Applying mvnpdf to multiple points in an array

조회 수: 2 (최근 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 CenterFile Exchange에서 Powertrain Blockset에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by