【问题标题】:Drawing rectangles with different angles with Psychtoolbox Matlab使用 Psychtoolbox Matlab 绘制不同角度的矩形
【发布时间】:2013-06-07 19:54:41
【问题描述】:

我正在绘制 4 个随机旋转的矩形。他们的天使似乎是随机的,但我需要他们有点不同。矩形不应彼此靠近,它们都应至少相隔 10 度。这也应该是随机的。我该如何定义这个?谢谢!

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);

【问题讨论】:

    标签: matlab random psychtoolbox


    【解决方案1】:

    而不是rot_angle1=randi(360); 行,定义

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

    现在每个角度至少相隔 10 度,步长为 10 度。请注意,这并不意味着角度是唯一的。使用randi 有可能两个旋转角度相同。为了强加唯一性使用

    rot_angle=randperm(36)*10;
    

    使用rot_angle(1) 代替rot_angle1 等。

    【讨论】:

    • 我试过了。但它们并不总是独一无二的。另外,你能解释一下35的原因吗?我不明白。谢谢。
    • 当我写独特时,我的意思是不重复。 randperm 确保你得到的随机数是不重复的,因为它只是将所有数字从 1 打乱到 N。35 的原因是一个错误,它实际上应该是 36。然后你从集合中生成一个随机数( 10,20,30...360)
    猜你喜欢
    • 1970-01-01
    • 2012-04-24
    • 2016-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多