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

조회 수: 4 (최근 30일)
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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by