vectorizing/simplifying randperm code

2 visualizaciones (últimos 30 días)
MiauMiau
MiauMiau el 4 de Mayo de 2015
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

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by