I'm drawing 4 rectangles with randomized rotations. They seem randomized in terms of their angels, however I need them to be a little bit different. The rectangles should not be close to each other, they all should be at least 10 degrees apart. And this also should be randomized. How can I define this? Thank you!

rot_angle1=randi(360); 
rot_angle2=randi(360); 
rot_angle3=randi(360); 
rot_angle4=randi(360); 
rect_array=255*ones(1,1);
t1=Screen('MakeTexture',w,rect_array);
t2=Screen('MakeTexture',w,rect_array);
t3=Screen('MakeTexture',w,rect_array);
t4=Screen('MakeTexture',w,rect_array);
t5=Screen('MakeTexture',w,rect_array);

destrect(1,:) = (ul_c + stim_array);
destrect(2,:) = (ur_c + stim_array);
destrect(3,:) = (ll_c + stim_array);
destrect(4,:) = (lr_c + stim_array);

Screen('DrawTexture',w,t2,[],destrect(1,:),rot_angle1);
Screen('DrawTexture',w,t3,[],destrect(2,:),rot_angle2);
Screen('DrawTexture',w,t4,[],destrect(3,:),rot_angle3);
Screen('DrawTexture',w,t5,[],destrect(4,:),rot_angle4);
Screen('Flip',w);
share|improve this question
up vote 0 down vote accepted

instead of rot_angle1=randi(360); lines, define

rot_angle=randi(36,1,4)*10;

Now there is at least 10 deg apart in each angle, with step size of 10 degrees. Note that this doesn't mean the angles will be unique. using randi there's a chance two rotation angles will be the same. In order to impose uniquness use

rot_angle=randperm(36)*10;

Use rot_angle(1) instead of rot_angle1 etc.

share|improve this answer
    
Great! Thank you! – Felis Jun 7 '13 at 21:17
    
Felis, see my edit regarding how to impose uniqueness of random angles... – bla Jun 7 '13 at 22:07
    
I tried that. Still they are not always unique. Also, can you explain the reason for 35? I don't get it. Thanks. – Felis Jun 7 '13 at 23:48
    
when I wrote unique I meant non-repeating. randperm assures that the random numbers you'll get are non repeating because it just scrambles all the numbers from one to N. The reason for 35 is a bug it should actually be 36. then you generate a random number from the set (10,20,30...360) – bla Jun 8 '13 at 0:38
    
Ok got it. thank you. – Felis Jun 8 '13 at 1:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.