vectorizing/simplifying randperm code
6 次查看(过去 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!