フィルターのクリア

how select random elements of array without replacement

6 ビュー (過去 30 日間)
zohre saeedi
zohre saeedi 2016 年 7 月 5 日
コメント済み: zohre saeedi 2016 年 7 月 5 日
I have a matrix A(1*N).[a11 a12 a13 a14 a15 a16 a17 .....] first,I want to select random m1 member of A without replacement .then I want to select m2 member without replacement that don't select befor step. and I want that don't select a14 in any step. can anybody help me to write matlab code of it?
  1 件のコメント
zohre saeedi
zohre saeedi 2016 年 7 月 5 日
how I know that don't select a14? and I want member of m1 be different from member of m2

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2016 年 7 月 5 日
編集済み: Stephen23 2016 年 7 月 5 日
The easiest way to do this is to use randperm: this provides a random selection without replacement. Note that randi uses replacement, so is not useful for your task.
Something like this:
>> A = 1:23;
>> excl = 4; % indices to exclude
>> B = A(~ismember(1:numel(A),excl));
>> idx = randperm(numel(B));
Where B contains all values of A except the elements at locations given in excl, and idx contains random indices without replacement for every element in B. Thus you can easily use these indices in a loop:
for k = 1:numel(B)
B(idx(k))
end
  1 件のコメント
zohre saeedi
zohre saeedi 2016 年 7 月 5 日
thanks for your help. your answer is very good.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by