我使用Matlab的随机样本函数以下列方式对数据点进行采样:
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。
发布于 2016-06-22 23:27:57
与其对数据使用randsample,不如对索引进行随机抽样,然后将这些索引转换为points中相应的值。
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)https://stackoverflow.com/questions/37979810
复制相似问题