Generate three dimensional arrays using mvnrnd in Matlab?
5 次查看(过去 30 天)
显示 更早的评论
I need to generate a three dimensional matrix B in Matlab using the command mvnrnd. In particular, let
mu=[0 0; -1 -3; 0 4; 2 4; 8 1]
and
sigma=repmat(1/(3^2)*eye(2),[1,1,5])
If I use the command
B= mvnrnd(mu,sigma)
I get a matrix 5x2 in which each row i is sampled from N(mu(i,:), sigma(:,:,i)). Instead, I want B to be 5x2xr, i.e. each row i is sampled from N(mu(i,:), sigma(:,:,i)) r times.
Could you help me?
0 个评论
回答(1 个)
dpb
2014-5-9
From
help mvnrnd
...
R = mvnrnd(MU,SIGMA,N) returns a N-by-D matrix R of random vectors
chosen from the multivariate normal distribution with 1-by-D mean
vector MU, and D-by-D covariance matrix SIGMA.
2 个评论
dpb
2014-5-9
Well, I should've read the doc all the way thru... :)
The third option doesn't replicate into a 3D sampling after all; it's still a 2D array returned.
Looks like you'll have to wrap the call in a loop to populate the planes or use accumarray w/ an anonymous function wrapper around the 2D result by plane.
另请参阅
类别
在 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!