MATLAB for Psychologists

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Mauro Borgo, Alessandro Soranzo and Massimo Grassi
Edition: 1
Publisher: Springer New York, New York, NY
Year: 2012

Language: English
Pages: 283

1 Basic Operations ..................................................................................... 1
Variables .................................................................................................... 5
Thinking in a Matrix Way ......................................................................... 8
Operations ................................................................................................. 15
Summary ................................................................................................... 17
Exercises ................................................................................................... 18
A Brick for an Experiment ........................................................................ 20
References ................................................................................................. 23
Suggested Readings .................................................................................. 23
2 Data Handling ......................................................................................... 25
Types of Variables (Logical Values, Strings, NaN, Structures, Cells) ...... 25
Logical Variables................................................................................... 25
Strings ................................................................................................... 31
NaN ....................................................................................................... 35
Structures .............................................................................................. 35
Cells ...................................................................................................... 38
Import/Export ............................................................................................ 40
Summary ................................................................................................... 42
Exercises ................................................................................................... 43
A Brick for an Experiment ........................................................................ 44
Read the Results .................................................................................... 44
Reference .................................................................................................. 46
Suggested Readings .................................................................................. 46
3 Plotting Data ............................................................................................ 47
Plot Data .................................................................................................... 47
Control the Plot’s Objects: Labels, Legend, Title… ................................. 50
Subplot: Multiple Plots in One Figure ...................................................... 52
3-D Plots ................................................................................................... 56
Printing and Saving Images ...................................................................... 58
Contents
xii Contents
Handle Graphics ........................................................................................ 58
Summary ................................................................................................... 61
Exercises ................................................................................................... 62
A Brick for an Experiment ........................................................................ 64
Plot the Results ..................................................................................... 64
Reference .................................................................................................. 65
Suggested Readings .................................................................................. 65
4 Start Programming ................................................................................. 67
M-Scripts and Functions ........................................................................... 67
Control Flow Statements........................................................................... 70
Cycles and Conditionals: If ................................................................... 70
Switch Case ........................................................................................... 72
For Loops ............................................................................................. 74
While .................................................................................................... 78
Break ..................................................................................................... 81
Try–Catch ............................................................................................. 82
Loops Versus Matrices and If Versus Logicals ..................................... 82
Functions ................................................................................................... 83
Scope of Variables ................................................................................. 86
Change the Number of Inputs and Outputs ........................................... 87
More on Data Import/Export: Script Examples ........................................ 90
Analysis ................................................................................................ 95
Guidelines for a Good Programming Style ............................................... 96
Writing Code ......................................................................................... 96
Debug .................................................................................................... 98
Summary ................................................................................................... 100
Exercises ................................................................................................... 101
A Brick for an Experiment ........................................................................ 102
Analysis ................................................................................................ 104
References ................................................................................................. 106
Suggested Readings .................................................................................. 106
5 A Better Sound ......................................................................................... 107
Generate a Sound ...................................................................................... 107
Multiple Sounds ........................................................................................ 112
Manipulating a Sound’s Level .................................................................. 114
Match the Level of Sound with Different Waveforms .......................... 115
Stereophonic Sounds for ITD and ILD ..................................................... 116
A Sound’s Envelope .................................................................................. 118
Sound Filtering.......................................................................................... 120
Sound Analysis.......................................................................................... 123
Summary ................................................................................................... 125
Exercises ................................................................................................... 125
Contents xiii
A Brick for an Experiment ........................................................................ 126
References ................................................................................................. 127
Suggested Readings .................................................................................. 128
6 Create and Proccess Images ................................................................... 129
Images Basics ............................................................................................ 129
Importing and Exporting Images .......................................................... 132
Display Images ...................................................................................... 134
Basic Manipulation of Images .................................................................. 135
Point Operations ........................................................................................ 136
Intensity Transformation ....................................................................... 136
Windowing ............................................................................................ 138
Neighborhood Processing ......................................................................... 140
The Edges of the Image ........................................................................ 144
Advanced Image Processing ..................................................................... 144
Creating Images by Computation ............................................................. 144
Summary ................................................................................................... 149
Exercises ................................................................................................... 150
References ................................................................................................. 151
Suggested Readings .................................................................................. 152
7 Data Analysis ........................................................................................... 153
Descriptive Statistics ................................................................................. 153
Measures of Central Tendency .............................................................. 153
Measures of Dispersion ......................................................................... 154
Bivariate and Multivariate Descriptive Statistics ..................................... 155
Covariance ............................................................................................ 156
Simple and Multiple Linear Regression ............................................... 156
Generalized Linear Model .................................................................... 160
Inferential Statistics .................................................................................. 162
Parametric Statistics .............................................................................. 162
t-Test ..................................................................................................... 163
ANOVA ................................................................................................. 166
Nonparametric Statistics ........................................................................... 177
Categorical Data .................................................................................... 177
Ordinal Data .......................................................................................... 179
Signal-Detection Theory (STD) Indexes .............................................. 182
Summary ................................................................................................... 184
Exercises ................................................................................................... 185
A Brick for an Experiment ........................................................................ 186
References ................................................................................................. 187
Suggested Readings .................................................................................. 187
xiv Contents
8 The Charm of Graphical User Interface ............................................... 189
Introduction ............................................................................................... 189
GUIDE ...................................................................................................... 189
Starting GUIDE .................................................................................... 190
The GUI Toolbar ....................................................................................... 190
Adding UiControls to the GUI .............................................................. 191
Closing the GUI .................................................................................... 193
Controlling UiControls from Other UiControls ........................................ 196
The Sum-Two-Numbers Example ........................................................ 196
Displaying Graphs and Figures in the GUI ........................................... 202
Saving User Input ..................................................................................... 204
Adding Your Own Functions ................................................................ 207
A Brick for an Experiment ........................................................................ 212
Appendix ................................................................................................... 215
The File Menu ....................................................................................... 216
The Edit Menu ...................................................................................... 216
The View Menu ..................................................................................... 217
The Layout Menu .................................................................................. 217
Tools Menu ........................................................................................... 218
Help ....................................................................................................... 218
Preferences for GUIDE ............................................................................. 219
Backward Compatibility ....................................................................... 220
Other Preferences .................................................................................. 221
Suggested Readings .................................................................................. 221
9 Psychtoolbox: Video ................................................................................ 223
The Screen Function ................................................................................. 223
Analysis ................................................................................................ 225
How to Use Screen to Get Information ..................................................... 225
How to Use Screen to Draw Figures ......................................................... 227
Preliminary Notions: Drawing Figures in Three Steps—Opening,
Drawing, and Closing ........................................................................... 227
Opening the Window ............................................................................ 227
Drawing: An Introduction ..................................................................... 229
Closing .................................................................................................. 230
Drawing: Reprise ...................................................................................... 230
Analysis ................................................................................................ 231
Drawing Shapes .................................................................................... 231
Batch Processing: Drawing Multiple Figures at Once .............................. 235
Drawing Text ............................................................................................. 236
Importing Images ...................................................................................... 238
Analysis ................................................................................................. 239
Video Clips ................................................................................................ 240
Analysis ................................................................................................. 240
Analysis ................................................................................................. 241
Drawing Things at the Right Time ............................................................ 241
Contents xv
Analysis ................................................................................................. 243
Summary ................................................................................................... 243
Exercises ................................................................................................... 244
Exercise 1 .............................................................................................. 244
Solution 1 .............................................................................................. 244
Exercise 2 .............................................................................................. 244
Solution 2 .............................................................................................. 245
A Brick for an Experiment ........................................................................ 245
References ................................................................................................. 248
Suggested Readings .................................................................................. 248
10 Psychtoolbox: Sound, Keyboard and Mouse ........................................ 249
Timing ....................................................................................................... 249
Priority ...................................................................................................... 250
Sound Functions........................................................................................ 251
Getting Participants’ Inputs: Keyboard and Mouse Functions ................. 253
Keyboard Response .............................................................................. 253
“Press Any Key to Proceed” ................................................................. 254
“Press the Spacebar to Proceed” ........................................................... 254
“Press Any Key to Respond” ................................................................ 256
Reaction-Time Detection ...................................................................... 256
Choice Reaction Time ........................................................................... 258
Go/No-Go Reaction Time ..................................................................... 259
Reaction Times Within a Video Clip..................................................... 260
Mouse Input .......................................................................................... 262
Using Participants’ Input to Manipulate Shape Characteristics ................ 263
Keyboard Manipulations ....................................................................... 264
Placing Discs with the Mouse ............................................................... 266
Summary ................................................................................................... 267
Exercises ................................................................................................... 268
Exercise 1 ............................................................................................. 268
A Brick for an Experiment ........................................................................ 269
References ................................................................................................. 272
Suggested Readings .................................................................................. 273
About the Authors ........................................................................................... 275
Index ................................................................................................................ 277