clc;
clear;
sr=44100;
gatedur=0.02;
pin=[100,300,500,700,900,1100];
gate=cos(linspace(pi,2*pi,sr*gatedur));%余弦变换
gate=(gate+1)/2;
offsetgate=fliplr(gate);
height=zeros(1,6);
time=zeros(1,6);
try
[CH,KU]=Screen('WindowSize', 0);
[M,N]=Screen('DisplaySize', 0);
INCH=sqrt(M^2+N^2)/2.54/10;
p1=deg2pix(1,INCH,CH,50,KU/CH);
KbName('UnifyKeyNames');
spaceKey= KbName('space');
escape= KbName('escape');
circleRadius = 30;
PsychDefaultSetup(2);
Screen('Preference', 'SkipSyncTests', 1);
w=Screen('OpenWindow',0,0,[0,0,500,500]);
circleColor = [0 0 255];
n=0;
i=1;
while n<6
sui=randi(6);
f=MakeBeep(pin(sui),0.2,44100);
sustain=ones(1,(length(f)-2*length(gate)));
envelope=[gate,sustain,offsetgate];
smoothed_tone=envelope.*f;
sound(smoothed_tone);
t0 = GetSecs;
exitFlag=false;
while ~exitFlag
[x, y, buttons] = GetMouse(w);
if any(buttons)
% Draw the circle at the clicked position
Rect=[250-circleRadius, y-circleRadius, 250+circleRadius, y+circleRadius];
Screen('FillOval',w, circleColor, Rect);
Screen('Flip', w);
end
[keyIsDown,seconds,keyCode]=KbCheck;
if keyIsDown
if keyCode(spaceKey)
height(1,i)=y;
time(1,i)=seconds-t0;
n=n+1;
break;
end
end
end
exitFlag=false;
continue;
end
sca;
catch ME
Screen('Close', w)
rethrow(lasterror)
end
把n=n+1语句移到if语句内部试试看👀
if keyCode(spaceKey)
height(1,i)=y;
time(1,i)=seconds-t0;
n=n+1;
break;
end
n=n+1;
1 grid on/off 网格打开和关闭
2 box on/off 打开和关闭上方和右方的坐标轴
3 axis on/off 打开关闭坐标轴
4 axis square 产生正方形坐标系
5 axis equal 纵横轴采用等长刻度(即它的tick是相等的)
6 axis equal tight: Set the axis limits to the range of the data
7 axis equal image: Let the plot box fits tightly around the data
8 axis ij: Place the origin of the coordinate system in the
upper left corner
9 axis xy: Place the origin in the lower left corner