how to control the presentative time of two types of stimulation respectively

Hi everyone,

  I have just learned the PTB 20 days, but I encountered thousands of problems. And I select one that don't make me looking stupid, maybe just looking or I looking...

  OK, my purpose is to present two same pictures on the two sides of the coherent motion. The effect picture in the attachment. Firstly, I got the produce of coherent motion and the produce of to present pictures, and then put them togther. Sounds good! But my problem arises, the time of pictures can't be setup. I put the produces below, and hoping somebody will point my fault. Nomatter who you are, thank you very much!


function [key rt starttime]=movingDots(wptr,dots,movingtime,validkeys)

%movingDots.m

%the dots has the following struct

%ndots

%speed

%color

%size

%direction

%lifttime

%center

%coherence

%aperturesize

key=[];

rt=0;

index=1;

nDots=sum([dots.ndots]);

colors = zeros(3,nDots);

size = zeros(1,nDots);

order=randperm(nDots);

for i=1:length(dots)

    %get aperturesize rectangular coordinates

    left(i)=dots(i).center(1)-dots(i).aperturesize(1)/2;

    top(i)=dots(i).center(2)-dots(i).aperturesize(2)/2;

    right(i)=dots(i).center(1)+dots(i).aperturesize(1)/2;

    bottom(i)=dots(i).center(2)+dots(i).aperturesize(2)/2;

    %generate random coordinates in the aperturesize

    dots(i).x=randi([left(i) right(i)],1,dots(i).ndots);

    dots(i).y=randi([top(i) bottom(i)],1,dots(i).ndots);

    direction=rand(1,dots(i).ndots)*360;

    ncoherent=ceil(dots(i).coherence*dots(i).ndots);

    direction(1:ncoherent)=dots(i).direction;

    dots(i).dx=dots(i).speed*sin(direction*pi/180);

    dots(i).dy=dots(i).speed*cos(direction*pi/180);

    dots(i).life=ceil(rand(1,dots(i).ndots)*dots(i).lifetime);

    id=index:(index+dots(i).ndots-1);

    if ischar(dots(i).color)

        colors(:,order(id))=randi([0 255],3,dots(i).ndots);

    else

        colors(:,order(id))=repmat(dots(i).color(:),1,dots(i).ndots);

    end

    size(order(id))=repmat(dots(i).size,1,dots(i).ndots);

    index=index+dots(i).ndots;

end

x=zeros(1,nDots);

y=zeros(1,nDots);

withindots=false(zeros(1,nDots));

drawFixM(wptr,8,4,255,1);%present the Fixation point

WaitSecs(0.5);

showF_inM(wptr,50,0.4); %present the two pictures

while KbCheck;

end

starttime=GetSecs;


while GetSecs-starttime<movingtime

    index=1;

    for i=1:length(dots)

        dots(i).x=dots(i).x+dots(i).dx;

        dots(i).y=dots(i).y+dots(i).dy;

        dots(i).x(dots(i).x<left(i))=dots(i).x(dots(i).x<left(i))+dots(i).aperturesize(1);

        dots(i).x(dots(i).x>right(i))=dots(i).x(dots(i).x>right(i))-dots(i).aperturesize(1);

        dots(i).y(dots(i).y<top(i))=dots(i).y(dots(i).y<top(i))+dots(i).aperturesize(2);

        dots(i).y(dots(i).y>bottom(i))=dots(i).y(dots(i).y>bottom(i))-dots(i).aperturesize(2);

        dots(i).life=dots(i).life+1;

        outsidedots = mod(dots(i).life,dots(i).lifetime)==0;

        dots(i).x(outsidedots)=randi([left(i) right(i)],1,sum(outsidedots));

        dots(i).y(outsidedots)=randi([top(i) bottom(i)],1,sum(outsidedots));

        id=order(index:(index+dots(i).ndots-1));

        

        withindots(id)=(dots(i).x-dots(i).center(1)).^2/(dots(i).aperturesize(1)/2)^2+(dots(i).y-dots(i).center(2)).^2/(dots(i).aperturesize(2)/2)^2<1;

        

        x(id)=dots(i).x;

        y(id)=dots(i).y;

        index=index+dots(i).ndots;

        

    end

    

    Screen('DrawDots',wptr,[x(withindots);y(withindots)],size(withindots),colors(:,withindots),[0 0],1);

    

    drawFixM(wptr,8,4,255);

   Screen('Flip',wptr);

    

    [kd secs keyCode]=KbCheck;

    if kd && any(keyCode(validkeys))

        rt=secs-starttime;

        key=find(keyCode==1);

        while KbCheck;end

        break;

    elseif kd && keyCode(KbName('escape'))

        rt=-1;

        key=-1;

        break;

    end

     

end


drawFixM(wptr,8,4,255,1);

 


function showF_inM(wptr,distanceF,time)

%distanceF is the distance between picture and moving dots. 

%the picture is 150*180 pixel; the aperturesize is 200*200 pixel

try

    pics=loadPicturesF(wptr,'bmp|ZF'); % my picture name is ZF1.bmp to ZF12.bmp

    picsFields=fieldnames(pics);

   [cx,cy]=WindowCenter(wptr);

   destinationrect=[cx-250-distanceF,cy-90,cx-100-distanceF,cy+90;cx+100+distanceF,cy-90,cx+250+distanceF,cy+90];

   Screen('DrawTextures',wptr,pics.(char(picsFields(randi(12)))).texture,[],destinationrect');

   WaitSecs(time);

catch

    psychrethrow(psychlasterror);

    sca;

end

return;