Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab中随机样本的索引位置_Matlab_Random - Fatal编程技术网

Matlab中随机样本的索引位置

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); 如何获取所选点的索引 例如,如果点

我使用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);
如何获取所选点的索引


例如,如果点=[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)