vectorizing/simplifying randperm code

2 ビュー (過去 30 日間)
MiauMiau
MiauMiau 2015 年 5 月 4 日
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 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by