南方医科大学:《心理学实验软件应用》课程教学资源(讲义)第七章 反应记录和数据保存分析 Key Presses and Data analysis

第七章按键反应的记录、保存 和数据分析 Key Presses and Data analysis
Key Presses and Data analysis

单个实验试次Tria的流程 01 呈现刺激 Psychtoolbox(PTB)中 的Screen函数 ??? 02 记录(按键)反应
Psychtoolbox(PTB)中 的Screen函数 呈 现 刺 激 ??? 记 录 ( 按 键 ) 反 应

7.1与PTB兼容的按键相关命令 ·新建一个m文件KbPractice ·功能:持续记录键盘上的按键,并在命令窗口显示对应的 按键数字码以及按键时间;按SPACE键结束记录。 1 号bPractice,m 2 Displays the number of seconds that have elapsed when the user presses a key. sa simplified version of KbDemo modified by YW,2022 >KbPractice %在命令窗口运行KbPractice Testing KbCheck and KbName:press a key to see its number Press the 'SPACE'key to exit. You pressed key 87 which is w typed at time 2.4043seconds You pressed key 69 which is e typed at time 3.5383seconds You pressed key 65 which is a typed at time 5.286seconds You pressed key 82 which is r typed at time 5.7581seconds You pressed key 70 which is f typed at time 6.828seconds You pressed key 49 which is 1!typed at time 12.7795seconds You pressed key 50 which is 23 typed at time 13.3814seconds You pressed key 51 which is 3 typed at time 13.8795seconds You pressed key 97 which is 1 typed at time 15.4673seconds You pressed key 98 which is 2 typed at time 15.7394seconds You pressed key 99 which is 3 typed at time 16.1774seconds You pressed key 32 which is space typed at time 18.0832seconds
l 新建一个m文件KbPractice • 功能:持续记录键盘上的按键,并在命令窗口显示对应的 按键数字码以及按键时间;按SPACE键结束记录。 %在命令窗口运行KbPractice

6 bName ('UnifyKevNames); WaitSecs(1.0); 8 disp('Testing KbCheck and KbName:preas a key to see ita number') 9 disp('Preas the 'SPACE''key to exit.'); 10 escapeKey KbName ('SPACE'); ●KbName %在命令窗口测试KbName ·实现键盘按键数字码和所表示的按键名称 之间的转换。 >KbName('a') .KbName('UnifyKeyNames') ans ·可以使程序使用在Windows.系统和Mac系 65 统下通用的按键 >KbName(65) .WaitSecs ans ·等待给定的时间,单位为秒。 a ●disp ·在命令窗口显示字符串
l KbName • 实现键盘按键数字码和所表示的按键名称 之间的转换。 l KbName(‘UnifyKeyNames’) • 可以使程序使用在Windows系统和Mac系 统下通用的按键 l WaitSecs • 等待给定的时间,单位为秒。 l disp • 在命令窗口显示字符串 %在命令窗口测试KbName

11 ListenChar (2); 12 while KbCheck;end Wait until all keys are released. 13 This is a loop that flips around doing anything as long as KbCheck 14 reports back that a key is pressed on the keyboard.Means that the 15s program doesn't continue until all keys have been released. ●ListenChar(2):监听除了Octave/MATLAB命令窗口以 外的按键行为 。m文件运行过程中记录到的按键不会显示在命令窗口 。ListenChar(O):恢复MATLAB命令窗口的监听状态,从 而可以执行命令窗口输入的命令
l ListenChar(2):监听除了Octave/MATLAB命令窗口以 外的按键行为 • m文件运行过程中记录到的按键不会显示在命令窗口 l ListenChar(0):恢复MATLAB命令窗口的监听状态,从 而可以执行命令窗口输入的命令

11 Listenchar (2): 12 while KbCheck;end Wait until all keys are released. 13This is a loop that flips around doing anything as long as KbCheck 14 sreports back that a key is pressed on the keyboard.Means that the 15sprogram doesn't continue until all keys have been released. 。KbCheck ●实时检查是否有按键行为,确保在开始实验前键盘的按键处于空闲 状态。 试-试:help KbCheck %这是函数KbCheck,三个输出变量,没有输入变量 [keylsDown,secs,keyCode]KbCheck; ·keylsDown:如果有按键被按到,keylsDown=1,KbCheck=1;如果没有按键, keylsDown=0,KbCheck=0 ●Secs:按键的电脑系统时刻点 ●keyCode: ●keyCode在Windows中是256*1的矩阵,每一个元素代表的是一个按键 ●如果某个按键(例如,第65个)被按到,那keyCode矩阵对应的元素(例如, 第65个元素)就为1,其他元素都为0 ●可通过find(keyCode)查看是哪个数字编码的按键 ●可通过KbName(keyCode)查看按键对应的字符是什么
l KbCheck l实时检查是否有按键行为,确保在开始实验前键盘的按键处于空闲 状态。 试一试:help KbCheck l [keyIsDown,secs,keyCode] = KbCheck; l keyIsDown:如果有按键被按到, keyIsDown=1, KbCheck=1;如果没有按键, keyIsDown=0, KbCheck=0 ; l Secs:按键的电脑系统时刻点 l keyCode: l keyCode在Windows中是256*1的矩阵,每一个元素代表的是一个按键 l 如果某个按键(例如,第65个)被按到,那keyCode矩阵对应的元素(例如, 第65个元素)就为1,其他元素都为0 l 可通过find(keyCode)查看是哪个数字编码的按键 l 可通过KbName(keyCode)查看按键对应的字符是什么 %这是函数KbCheck,三个输出变量,没有输入变量

11 ListenChar(2); 12 while KbCheck;end Wait until all keys are released. 13 &This is a loop that flips around doing anything as long as KbCheck 14 reports back that a key is pressed on the keyboard.Means that the 15sprogram doesn't continue until all keys have been released. ●while KbCheck;end ·只要KbCheck=1(检查到有按键被按住),就一直保持按键检查 状态,直到没有任何一个按键被按住,即所有按键都处于空闲状态, 为随后“正式”开始检查按键行为做好准备
l while KbCheck; end • 只要KbCheck=1(检查到有按键被按住),就一直保持按键检查 状态,直到没有任何一个按键被按住,即所有按键都处于空闲状态, 为随后“正式”开始检查按键行为做好准备

17 18曰whi1e1 %GetSecs获取当前电脑系统时间 19 swhile 1 is always true,so this loop will continue indefinitely. 20 Line 28 forceably breaks us out of the loop if the escape key is 21 号pressed 22 23 Check the state of the keyboard. 24 See if a key is currently pressed on the keyboard.If not,we skip 25 s the next for loop from lines 20-38,and basically check again almost 26 &immediately. 27 28 【keyIsDown,seconds,keyCode】=KbCheck; %KbCheck检查是否有按键行为 29 30 If the user is pressing a key, then display its code number and name. 32白 if keyIsDown %如果检测到按键行为,显示按键内容及时间 33 34 Note that we use find(keyCode)because keyCode is an array. 35 str=['You pressed key 'num2str(find(keyCode)),'which is',KbName(keyCode),'typed at time ',. num2str(seconds startsecs),'seconds']: 37 %是字符跨行连接符 8 disp(str); 39 Display which key has been pressed. 40 41 If the key that has been pressed is the escape key break out of all loops including the indefinite while loop. 43白 if keyCode(escapekey) 44 break; %如果检测到的按键行为是结束键,则break, 45 end 96 跳出while7end'死循环 while KbCheck;end If the user holds down a key for more than a microsecond, 49 KbCheck will report multiple events,since computers are faster 50 than people's fingers 51 To condense multiple 'keyDown'events into a single event, 52 tonce a key has been pressed 53 we wait until all keys have been released 54 sbefore going through the loop again 56 end -end 58 Listenchar(0);
%KbCheck检查是否有按键行为 %如果检测到按键行为,显示按键内容及时间 %如果检测到的按键行为是结束键,则break, 跳出while 1 end‘死循环’ %GetSecs获取当前电脑系统时间 %.是字符跨行连接符

7.2与PTB兼容的按键相关函数1 。新建一个函数m文件waitTilltime.m ·在给定时间内记录并存储按键内容及时间。 %这是函数wait Tilltime,两个输出变量,两个输入变量(第2个输入变量不是必须) 月Function[keys,RT】=wa1tT111time(waitTime,startTime】 3 [keys,RT]waitTill(waitTime,[startTime]) Returns a vector of keys pressed and the timing of the presses during an sinterval of 'waitTime'seconds.By default,the clock starts within the > sfunction,but if startTime is provided then the function will return swaitTime seconds after startrime was defined with 'GetSecs'. 10 An empty variable is returned if no key was pressed during the interval. 11 12 3/24/09 Written by G.M.Boynton at the University of Washington >[keys,RT]waitTilltime(8) >>[keys,RT]waitTilltime(5) keys keys ::%在命令窗口运行函数waitTilltime 1.31=3 RT= 2.2399 3.56174.2635 RT= 1.41351.59361,76351,96952.2353.2.4215
l 新建一个函数m文件waitTilltime.m • 在给定时间内记录并存储按键内容及时间。 %这是函数waitTilltime,两个输出变量,两个输入变量(第2个输入变量不是必须) %在命令窗口运行函数waitTilltime

14 sInitialize the output variables 15 keys =() 16 RT=[]: 17 18 Read the clock if no clock time was provided 19if ~exist ('startTime') 20 startTime GetSecs; 21 end 22 23 sGive a warning if the waiting interval is zero or less 24if GetSecs-startTime waitTime 25 disp('Warning!waitTill:waiting interval is less than zero') 26 end 27 8 sTurn off the output to the command window 29 ListenChar(2); Q:如何设置必须要按键才行? 3 nKeys 0; sloop until waitTime seconds has passed since startTime was defined 33 while GetSecs-startTime waitTime %如果还处在等待按键反应的时间内 34 ssee if a key is pressed 35 【keyIsDown,timeSecs,keyCode】=bCheck;.%检查按键行为 36白 if keyIsDown sa key is down:record the key and time pressed 37 nKeys-nKeys+i;%计算总的按键次数 38 RT(ney3)=timeSeca3-3 cartTime:%计算当次按键反应时间(当前时间-起始时间) 39 keys(nKeys)=KbName(keyCode) 40 sclear the keyboard buffer %查看按键内容 41 while KbCheck:end 42 end 43 end sTurn on the output to the command window 45 ListenChar(0); 46
%如果还处在等待按键反应的时间内 %检查按键行为 %计算总的按键次数 %计算当次按键反应时间(当前时间-起始时间) %查看按键内容 Q:如何设置必须要按键才行?
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 南方医科大学:《心理学实验软件应用》课程教学资源(讲义)第六章 心理学工具箱 Psychotoolbox PTB.pdf
- 南方医科大学:《心理学实验软件应用》课程教学资源(讲义)第四章 变量类型和函数 Variable Types and Functions.pdf
- 南方医科大学:《心理学实验软件应用》课程教学资源(讲义)第三章 矩阵运算与逻辑操作 Matrices and Logical operations(PPT).pptx
- 南方医科大学:《心理学实验软件应用》课程教学资源(讲义)第一二章 编程简介、字符串和向量 Strings and Vectors.pdf
- 《心理学实验软件应用》课程教学资源(参考书籍)MATLAB for Psychologists(Mauro Borgo, Alessandro Soranzo, Massimo Grassi, 2012).pdf
- 《心理学实验软件应用》课程教学资源(参考书籍)MATLAB for Behavioral Scientists(Second Edition, David A. Rosenbaum, Jonathan Vaughan, and Brad Wyble, 2015).pdf
- 电子工业出版社:《PSYCHTOOLBOX工具箱及MATLAB编程实例》参考书籍教材电子版(共十三章,编著:冯成志).pdf
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第12章 音乐治疗法.doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第11章 危机干预.doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第10章 网络心理.doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第8章 学习心理.doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第7章 爱情与性心理.doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第6章 人际交往与大学生心理健康.doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第5章 人格与大学生心理健康.doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第4章 情绪与大学生心理健康.doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第3章 自我意识与大学生心理健康.doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第2章 新生与环境适应.doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学资源(授课教案)第1章 绪论(负责人:冯宪萍).doc
- 山东第一医科大学(泰山医学院):《大学生心理健康教育》课程教学大纲 Mental Health Education of College Student.doc
- 南方医科大学:《认知心理学》课程教学资源(课件讲稿)记忆的认知神经机制-课件-王优.pdf
- 南方医科大学:《心理学与生活》课程教学课件(讲稿)第一讲 故事与人生——叙事治疗的启发(主讲:赵静波).pdf
- 南方医科大学:《心理学与生活》课程教学课件(讲稿)第二讲 死亡焦虑的意义——存在主义治疗的启发.pdf
- 南方医科大学:《心理学与生活》课程教学课件(讲稿)第三讲 和自己在一起——正念训练的启发.pdf
- 南方医科大学:《心理学与生活》课程教学课件(讲稿)第四讲 认识你的防御机制——精神分析治疗的启发.pdf
- 南方医科大学:《心理学与生活》课程教学课件(讲稿)第五讲 转换生活的视角——认知治疗的启发.pdf
- 南方医科大学:《心理学与生活》课程教学课件(讲稿)第六讲 塑造你的行为——行为主义治疗的启发.pdf
- 南方医科大学:《广告与消费心理学》课程教学资源(课件讲稿)消费心理学概述(主讲:刘晓秋).pdf
- 南方医科大学:《广告与消费心理学》课程教学资源(课件讲稿)消费者的认知心理.pdf
- 南方医科大学:《广告与消费心理学》课程教学资源(课件讲稿)消费者购买决策及影响因素.pdf
- 《学前教育研究》:再论进化、发展和儿童早期教育(华南师范大学:杨宁).pdf
- 华东师范大学:如何进行教育实验研究(PPT讲稿,主讲:陶保平).ppt
- 《儿童心理学》书籍电子版〔瑞士〕J.皮亚杰B.英海尔德,The Psychology Of The Child(共六章).pdf
- 《中小学美术教学论》课程教学资源(文献资料)卡尔·威特——亲子教育的经验和方法(共十六章).pdf
- 《民族教育研究》:回到原点——教育人类学的本体性问题初探(华东师范大学:李政涛).pdf
- 安徽师范大学:课程思政教学设计汇编(共九门课程部分章节).pdf
- 石河子大学:《大学生心理健康教育》课程教学大纲 college students ' mental health education(负责人:马智群).doc
- 石河子大学:《大学生心理健康教育》课程教学资源(校刊)《心韵》第一期.pdf
- 石河子大学:《大学生心理健康教育》课程教学资源(校刊)《心韵》第二期.pdf
- 石河子大学:《大学生心理健康教育》课程教学案例集锦.pdf
- 石河子大学:《大学生心理健康教育》课程教学课件(PPT讲稿)专题一 心理健康概述与大学生心理适应.ppt