Create random permutations of an array of decimals or a vector of decimals.

4 ビュー (過去 30 日間)
Dennis_Pana
Dennis_Pana 2016 年 1 月 24 日
回答済み: Walter Roberson 2016 年 1 月 24 日
If i have the following vector [0;0.25;0.75;0.5], how i can create 2 or 3 or n permutations? I cannot use randperm, because works only with integers. Thank you in advance!
  2 件のコメント
John D'Errico
John D'Errico 2016 年 1 月 24 日
編集済み: John D'Errico 2016 年 1 月 24 日
Hmm. You cannot use the numbers that randperm will produce as indexes into the vector in question? Gosh, I thought you could do that. So this won't work at all:
v = [0;0.25;0.75;0.5],
ind = randperm(numel(v));
v(ind)
I really thought that would work too. Maybe you should try it? :)
Dennis_Pana
Dennis_Pana 2016 年 1 月 24 日
It works!! How i can create 2 or 3 or n different permutations without using a for loop? Thank you again!

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

採用された回答

Walter Roberson
Walter Roberson 2016 年 1 月 24 日
N = 3;
v = [0;0.25;0.75;0.5];
[~, idx] = sort(rand(N, length(v)), 2);
permuted_v = v(idx);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by