Matlab中随机样本的索引位置
我使用Matlab的randsample函数以以下方式对数据点进行采样:Matlab中随机样本的索引位置,matlab,random,Matlab,Random,我使用Matlab的randsample函数以以下方式对数据点进行采样: 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); 如何获取所选点的索引 例如,如果点
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。而不是对数据使用
randsample
,随机采样索引,然后将这些索引转换为点中相应的值
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)
不要对数据使用randsample
,而是对索引进行随机采样,然后将这些索引转换为点中相应的值
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)