matlab - 连接/叠加两个样本matlab

标签 matlab

我想将 2 个样本与 Sample_2 的偏好连接起来:

eg. Sample_1= rand(1000,28), Sample_2=normrnd(1.91,0.266,1000,28)

enter image description here

好的,现在我想将 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/

相关文章:

graphics - 如何更改单元 :Characters in Matlab?

python - PyCharm 工作区

matlab - 模拟互联网视频流中的丢包

python - 是否有相当于 MATLAB 的 conv2(h1,h2,A ,'same' ) 的 python ?

matlab - 使用通配符 MatLab 读取单个图像文件

matlab - 在 Matlab 中,为什么 cellfun(@size, x) 不需要非标量值的 UniformOutput False?

matlab - 在 MATLAB 中不使用 `size` 查找矩阵的大小

Matlab:方便地下标+挤压

matlab - 香农的熵计算

python - 将python字典转换为MATLAB