Filter löschen
Filter löschen

Applying mvnpdf to multiple points in an array

2 Ansichten (letzte 30 Tage)
Eric
Eric am 20 Okt. 2018
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!

Antworten (0)

Kategorien

Mehr zu Powertrain Blockset finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by