我有一个包含200个条目的4维数据集。我将在此数据集中生成随机值。我在下面声明了变量:
mu = median(Input,2)'; % find the median of Input as MU
sigma = [2 1; 1 4]; % SIGMA
Data = mvnrnd(mu,sigma,10)'; % Generate random number with "mvnrnd" function
但是,MATLAB给出了如下错误:
SIGMA must be a square matrix with size equal to the number of columns in MU, or a row vector with length equal to the number of columns in MU.
我认为," mvnrnd"函数不能生成超过2D的数据。
你能告诉我一下吗?
答案 0 :(得分:1)
错误告诉ou mu
不是行向量,因为你取行的中位数,只需转置它:
mu = median(Input,2).';
这是创建正半正定矩阵的一种方法:
temp = rand(numel(mu));
sigma = temp.'*temp;
Data = mvnrnd(mu,sigma ,100);
或者,您可以将sigma
定义为行向量:
sigma = [2 1 1 4];
我不知道您如何选择sigma
,但上面的示例显示您可以使用mvnrnd
创建超过2-D多元正态分布。< / p>