我想将 2 个样本与 Sample_2 的偏好连接起来:
eg. Sample_1= rand(1000,28), Sample_2=normrnd(1.91,0.266,1000,28)
好的,现在我想将 Sample_2
叠加到 Sample_1
上,但优先考虑sample_2 的点(例如 80% 的样本 2 和 20% 的样本 1)。即我想要更多的 Sample_2 点和更少的 Sample_1 点。这是为了对模型的蒙特卡罗采样进行不确定性分析。
也许是这样的:
Total_sample=randsample([Sample_1 Sample_2],1000,28,'false',[0.8 0.2]);
Error using randsample (line 74) POPULATION must be a vector.
和
Error using randsample (line 90) W must have length 56.
最佳答案
最简单的方法是生成随机索引,并使用它们用 Sample_2
中的样本覆盖 Sample_1
中 80% 的样本:
%// Copy samples from Sample_1
Total_Sample = Sample_1;
%// Overwrite 80% of the samples with values from Sample_2
N = numel(Sample_1);
idx = randperm(N);
Total_Sample(idx(1:0.8 * N)) = Sample_2(idx(1:0.8 * N));
或者,第二部分也可以这样实现:
N = numel(Sample_1);
idx = randsample(1:N, 0.8 * N);
Total_Sample(idx) = Sample_2(idx);
关于matlab - 连接/叠加两个样本matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15946007/