Randomizing Shape and Location

2 Ansichten (letzte 30 Tage)
Brett
Brett am 23 Nov. 2012
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,

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 23 Nov. 2012
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 Kommentare
Walter Roberson
Walter Roberson am 23 Nov. 2012
shiftedtriangle = triangle + repmat([xoffset, yoffset], 3, 1);
Brett
Brett am 23 Nov. 2012
You are the best Walter - works great!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by