Randomizing Shape and Location
2 次查看(过去 30 天)
显示 更早的评论
Hi Matlab community, I love you guys. I'm using psychtoolbox and I am trying to randomize four direction of an triangle in four different locations so that it 1) won't appear in same direction as any other triangle, 2) it won't appear in the same location as any other triangle.
Problem 1: If left triangle quadrant 4, then no other left triangles will appear and no other triangles will appear in the left quadrant.
colarray = [c1; c2; c3; c4];
colidx1 = randi(4,1,1);
colour1 = colarray(colidx1,:);
colidx2 = randi(4,1,1);
while ismember(colidx2, colidx1)
colidx2 = randi(4,1,1);
end
...
This will randomize the color between 4 different colors, and it works beautifully. So I know I can do the same thing for 1 feature, like direction. But I don't know how to do it for two features: direction and location.
Problem 2:
uptriangle = [50 0;0 -50;-50 0]+600
Screen('FillPoly', window, [255 255 0], uptriangle)
Screen('Flip',window);
This code creates an upwards facing triangle, but its location and its shape are defined by the same information - [50 0;0 -50;-50 0]+600. Is there anyway I can move its location without changing its shape? Maybe something like uptriangle = triangle + xyquandrant, triangle = [50 0;0 -50;-50 0], xyquadrant = [300,300]? If I cannot define its shape and location separately, I don't think I will be able to randomize them separately.
Please help,
0 个评论
采纳的回答
Walter Roberson
2012-11-23
I do not understand about "direction" ?
Yes you can move an object without changing its shape:
triangle = [50 0;0 -50;-50 0];
xoffset = 350; %for example
yoffset = 192; %or example
shiftedtriangle = triangle + repmat([xoffset; yoffset], 1, 3]);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image display and manipulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!