필터 지우기
필터 지우기

Randomizing Shape and Location

조회 수: 6 (최근 30일)
Brett
Brett 2012년 11월 23일
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,

채택된 답변

Walter Roberson
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]);
  댓글 수: 4
Walter Roberson
Walter Roberson 2012년 11월 23일
shiftedtriangle = triangle + repmat([xoffset, yoffset], 3, 1);
Brett
Brett 2012년 11월 23일
You are the best Walter - works great!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by