vectorizing/simplifying randperm code
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi
The idea of my code is the following:
If for instance I have the three "sequences":
(1) 12345 (2) 56789 (3) 43789
And an array of length n, my algorithm choses one of the three sequences at random for array(1). For array(2) the algorithm should chose one of the not yet chosen sequences at random, and array(3) takes the left-over sequence. For array(4) (i.e. arrar(number of sequences +1) the entire procedure restarts. Below my code - could it be done any better/faster?
function x = RandomizeTrials(numberofSeq, lengthofArray, SequenceArray)
N = lengthofArray/numberofSeq;
x = [];
for i=1:N
x = [x randperm(numberofSeq)];
end
for i = 1:length(SequenceArray)
for j = 1:length(x)
if x(j) == i
x(j) = SequenceArray(i);
end
end
end
end
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!