I want to use mvnrnd for generating numbers,but there is error in my code
1 回表示 (過去 30 日間)
古いコメントを表示
% Multivariate normal random numbers
% Gaussian mean and covariance
d = 31; % number of dimensions
mu = rand(1,d);
sigma = rand(d,d);
sigma = sigma*sigma';
% generate 100 samples from above distribution
N = 100;
Z = mvnrnd(mu, sigma, N);
% plot samples (only for 2D case)
scatter(Z(:,1), Z(:,2), 'filled'),
hold on
x = -3:.2:3;
y = -3:.2:3;
[X,Y]=meshgrid(x ,y);
X = [X Y];
Y=mvnpdf(X,mu,sigma)
Y=reshape(Y,length(x),length(y));
%ezcontour(@(x,y) mvnpdf(X, mu, sigma), xlim(), ylim())
title('Latin Hypercube Sampling')
xlabel('Z_1');
ylabel('Z_2');
0 件のコメント
回答 (3 件)
Benjamin Thompson
2022 年 6 月 13 日
X has 31 columns. mu only has 2 columns since d == 2. Both need to have the same number of olumns. sigma needs to have the same number of columns and rows as the number of columns in X.
Walter Roberson
2022 年 6 月 14 日
X = [X Y];
Before that statement X and Y are each 31 x 31. That statement puts them together to get a 31 x 62
Y=mvnpdf(X,mu,sigma)
mu is 1 x 31 but X is (now) 31 x 62 and that is incompatible size.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!