3

I have a sequence

A = 1:5

then I did its random permutation by

B = perms(A)
C = B(randperm(size(B,1)), :)

then I took a sample of 5 sequence randomly as follow

sample = C(1:5,1:4)

then I took a random sequence from sample as follow

randomRow = sample(randi(size(sample,1)),:)

I use the above random row for my operation. Now I am stuck how to select another row from a sample and do same operation on it, until I do operation on all rows in a sample and each row is not repeated from sample once it's processed.

2 Answers 2

4

you can use the below code:

For i=randperm(size(sample,1))
    Rand_row=sample(i,:)
    %// operate on Rand_row
End
Sign up to request clarification or add additional context in comments.

Comments

3

Why not just use the same trick you used earlier with randperm to shuffle the rows of sample and then just iterate through them?

sample_shuffled = sample(randperm(5),:)
for s = 1:5
    randomRow = sample_shuffled(s,:)
    %// Operate on randomRow
end 

2 Comments

Dan, how to put the result of each row operation in some different place so in end i can see the output of each operation i perform on each row. ?
in the loop do something like outputs(s) = ... but don't forget to preallocate memory for outputs before your loop to avoid growing the variable in the loop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.