首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >随机样本在Matlab中的索引位置

随机样本在Matlab中的索引位置
EN

Stack Overflow用户
提问于 2016-06-22 23:22:32
回答 1查看 498关注 0票数 0

我使用Matlab的随机样本函数以下列方式对数据点进行采样:

代码语言:javascript
复制
points = randi(100,1,10);
weighting_vector = rand(1,10);
normalized_weighting_vector = weighting_vector ./ sum(weighting_vector);
point = randsample(points,1,'true',normalized_weighting_vector);

如何获得所选点的索引?

例如,如果点= 1,2,2,3, 4,4,4,8,9,3和点=4,我想知道所选值的索引位置,可以是5、6或7。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-22 23:27:57

与其对数据使用randsample,不如对索引进行随机抽样,然后将这些索引转换为points中相应的值。

代码语言:javascript
复制
points =  [1,2,2,3,4,4,4,8,9,3];

% Randomly choose N indices from the possible index values for points
index = randsample(1:numel(points), 1, true);

% Get the point corresponding to these indices
point = points(index)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37979810

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档