在Matlab中对特定行进行采样 [英] Sample specific rows in matlab

查看:121
本文介绍了在Matlab中对特定行进行采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,其中存在一个维度为N x 1的Label矩阵. 标签矩阵中的示例条目如下

I have a scenario in which there is a Label matrix of dimension N x 1. The example entries in the label matrix is given below

Label = [1; 3; 5; ....... 6]

我想随机抽样,标签1的'm1'记录,标签2的'm2'记录等,以使输出LabelIndicatorMatrix(N x 1维)看起来像

I would like to random sample 'm1' records of label1, 'm2' records of label2 etc. so that the output LabelIndicatorMatrix (N x 1 dimension) look something like

LabelIndicatorMatrix = [1; 1; 0;.....1]

1代表已选择记录,0代表在采样期间未选择记录.输出矩阵满足以下条件

1 represent record has been chosen, 0 represent record not chosen during sampling. The output matrix satisfies the following condition

Sum(LabelIndicatorMatrix) = m1+m2...m6

推荐答案

您可以从以下代码示例开始,它选择标签向量的随机样本,并查找至少已选择一次标签向量的值:

you could start with this little sample of code, it selects random samples of your label vector and find which values of your label vector have been selected at least once:

Label = [1; 3; 5; ....... 6];
index = randi(N,m1,1);
index = unique(index);
LabelIndicatorMatrix = zeros(N,1);
LabelIndicatorMatrix(index)=1;

那表示我不确定我是否了解LabelIndicatorMatrix的最终条件.

That said I am not sure I understand the final condition on the LabelIndicatorMatrix.

这篇关于在Matlab中对特定行进行采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆