Hi Erik,
One solution:
for j = 1:5
for i = randperm(10)
....
end
end
randperm(n) returns a random permutations of numbers from 1 to n. You also know that after defining a vector like
v = [2 3 1 4 5 3]; % for example
it is perfectly legitimate to write it into your for loop as follows:
for counter = v
...
end
so that the counter is going to take the values in v. That is, 2, 3, 1 ...
Best.
"Erik L" <lookgrn@gmail.com> wrote in message <hu6c6s$mpo$1@fred.mathworks.com>...
> This is my simple for loop:
>
> for j=1:5,
> for i=1:10,
>
> whatever operation
>
> end
> end
>
> i want to make it randomize, like the FOR LOOP for i iterates by picking from 1 to 10(each and once) randomly for each normal iteration of j.
>
> for example for j=1, i need i to be iterated like:
>
> i=[2 4 5 3 1 .....] randomly and each one once in a set [1 to 10].
>
> and similarly for each iteration of j, the loop for i should iterate randomly.
>
>
> Is there a way to solve it in Matlab.
>
> Many thanks
>
> Erik. L
