logo资料库

Matlab for brain and cognitive science.pdf

第1页 / 共572页
第2页 / 共572页
第3页 / 共572页
第4页 / 共572页
第5页 / 共572页
第6页 / 共572页
第7页 / 共572页
第8页 / 共572页
资料共572页,剩余部分请下载后查看
Front Cover
Contents
Preface
Part I: Introductions
1 What Is MATLAB and Why Use It?
1.1 “I Want to Be a Scientist; Do I Also Need to Be a Good Programmer?”
1.2 Octave
1.3 Python, Julia, C, R, SPSS, HTML, and So Forth
1.4 How Long Does It Take to Become a Good Programmer?
1.5 How to Learn How to Program
1.6 The Three Steps of Programming
1.7 How Best to Learn from This Book
1.8 Exercises and Their Solutions
1.9 Written Interviews
1.10 Where Is All the Code?
1.11 Can I Use the Code in This Book for Real Data Analyses?
1.12 Is This Book Right for You?
1.13 Are You Excited?
2 The Philosophy of Data Analysis
2.1 Keep It Simple
2.2 Stay Close to the Data
2.3 Understand Your Analyses
2.4 Use Simulations, but Trust Real Data
2.5 Beware the Paralysis of Analysis
2.6 Be Careful of Overfitting
2.7 Noise in Neuroscience Data
2.8 Avoid Circular Inference
2.9 Get Free Data
3 Do Replicable Research
3.1 Avoid Mistakes in Data Analysis
3.2 Have a “Large Enough” N
3.3 Maximize Level 1 Data Count
3.4 Try Different Analysis Parameters, and Trust Analytic Convergence
3.5 Don’t Be Afraid to Report Small or Null Effects, but Be Honest About Them
3.6 Do Split-Half Replication
3.7 Independent Replications
3.8 Write a Clear Methods Section
3.9 Make Your Analysis Code or Data Available
4 The MATLAB Program
4.1 The MATLAB Program Graphical User Interface
4.2 Layouts and Visual Preferences
4.3 Color-Coordinating MATLAB
4.4 Where Does the Code Go?
4.5 MATLAB Files and Formats
4.6 Changing Directories inside MATLAB
4.7 The MATLAB Path
4.8 Comments
4.9 Cells
4.10 Keyboard Shortcuts
4.11 Help Box and Reporting Variable Content
4.12 The Code Analyzer
4.13 Back Up Your Scripts, and Use Only One Version
4.14 MATLAB Etiquette
5 Variables
5.1 Creating and Destroying Variables
5.2 Whos Are My Variables?
5.3 Variable Naming Conventions and Tips
5.4 Variables for Numbers
5.5 Variables for Truth
5.6 Variables for Strings
5.7 Variables for Cells
5.8 Variables for Structures
5.9 The Colon Operator
5.10 Accessing Parts of Variables via Indexing
5.11 Initializing Variables
5.12 Soft-coding versus Hard-coding
5.13 Keep It Simple
5.14 Exercises
6 Functions
6.1 Introduction to Functions
6.2 Outputs as Inputs
6.3 Multiple Inputs, Multiple Outputs
6.4 Help
6.5 Functions Are Files
6.6 Writing Your Own Function
6.7 Functions in Functions
6.8 Arguments In
6.9 Think Global, Act Local
6.10 Stepping into Functions
6.11 When to Use Your Own Functions
6.12 When to Modify Existing Functions
6.13 Timing Functions Using the Profiler
6.14 Exercises
7 Control Statements
7.1 The Anatomy of a Control Statement
7.2 If-then
7.3 For-loop
7.4 Skipping Forward
7.5 While-loop
7.6 Try-catch
7.7 Switch-case
7.8 Pause
7.9 Exercises
8 Input-Output
8.1 Copy-Paste
8.2 Loading .mat Files
8.3 Saving .mat Files
8.4 Importing Text Files
8.5 Exporting Text Files
8.6 Importing and Exporting Microsoft Excel Files
8.7 Importing and Exporting Hardware-Specific Data Files
8.8 Interacting with Your Operating System via MATLAB
8.9 Exercises
9 Plotting
9.1 What You Need to Know Before You Know Anything Else
9.2 Plotting Lines
9.3 Bars
9.4 Scatter Plots
9.5 Histograms
9.6 Subplots
9.7 Patch
9.8 Images
9.9 Get, Set, and Handle
9.10 Text in Plots
9.11 Interacting with MATLAB Plots
9.12 Creating a Color Axis
9.13 Saving Figures as Picture Files
9.14 Exercises
Part II: Foundations
10 Matrix Algebra
10.1 Vectors
10.2 Vector Addition and Multiplication
10.3 Matrices
10.4 Finding Your Way around a Matrix
10.5 Matrix Multiplication
10.6 When to Use .* and ./ versus * and / ?
10.7 Linear Independence and Rank
10.8 The Matrix Inverse
10.9 Solving Ax = b
10.10 Making Symmetric Squares from Rectangles
10.11 Full and Sparse Matrices
10.12 Exercises
11 The Fourier Transform
11.1 Sine Waves
11.2 The Imaginary Operator and Complex Numbers
11.3 The Complex Dot Product
11.4 Time Domain and Frequency Domain
11.5 The Slow Fourier Transform
11.6 Frequencies from the Fourier Transform
11.7 The Fast Fourier Transform
11.8 Fourier Coefficients as Complex Numbers
11.9 DC Offsets in the Fourier Transform
11.10 Zero-Padding the Fourier Transform
11.11 The Inverse Fourier Transform
11.12 The 2D Fourier Transform
11.13 Exercises
12 Convolution
12.1 Time-Domain Convolution
12.2 The Convolution Theorem
12.3 Convolution Implemented in the Frequency Domain
12.4 Convolution in Two Dimensions
12.5 Exercises
13 Interpolation and Extrapolation
13.1 The MATLAB Functions griddedInterpolant and scatteredInterpolant
13.2 Interpolation in Two Dimensions Using scatteredInterpolant
13.3 Using interp* Functions
13.4 Zero-Padding Theorem and Zero-Padding
13.5 Down-sampling
13.6 Exercises
14 Signal Detection Theory
14.1 The Four Categories of Correspondence
14.2 Discrimination
14.3 Isosensitivity Curves (a.k.a. ROC Curves)
14.4 Response Bias
14.5 Conditional Accuracy Functions
14.6 Exercises
15 Nonparametric Statistics
15.1 The Idea of Permutation-Based Statistics
15.2 Creating an Empirical Null Hypothesis Test
15.3 Creating a Null Hypothesis Distribution
15.4 Evaluating Significance
15.5 Example with Real Data
15.6 Extreme Value–Based Correction for Multiple Comparisons
15.7 Meta-permutation Tests
15.8 Exercises
16 Covariance and Correlation
16.1 Simulating and Measuring Bivariate Covariance
16.2 Multivariate Covariance
16.3 From Covariance to Correlation
16.4 Pearson and Spearman Correlations
16.5 Statistical Significance of Correlation Coefficients
16.6 Geometric Interpretation of Correlation
16.7 Exercises
17 Principal Components Analysis
17.1 Eigendecomposition
17.2 Simple Example with 2D Random Data
17.3 PCA and Coordinate Transformation
17.4 Eigenfaces
17.5 Independent Components Analysis
17.6 Exercises
Part III: Analyses of Time Series
18 Frequency Analyses
18.1 Blitz Review of the Fourier Transform
18.2 Frequency Resolution
18.3 Edge Artifacts and Data Tapering
18.4 Many FFTs for Many Trials
18.5 Defining and Extracting Frequency Ranges
18.6 Effects of Nonstationarities
18.7 Spectral Coherence
18.8 Steady-State Evoked Potentials
18.9 Exercises
19 Time-Frequency Analysis
19.1 Complex Morlet Wavelets
19.2 Morlet Wavelet Convolution
19.3 From Line to Plane
19.4 From Single Trial to Super-trial
19.5 Edge Artifacts
19.6 STFFT
19.7 Baseline Normalization
19.8 Time-Frequency Analysis in Real EEG Data
19.9 Exercises
20 Time Series Filtering
20.1 Running-Mean Filter
20.2 Running-Median Filter
20.3 Edges in the Frequency Domain
20.4 Gaussian Narrow-Band Filtering
20.5 Finite Impulse Response Filter
20.6 The Hilbert Transform
20.7 Exercises
21 Fluctuation Analysis
21.1 Root Mean Square to Measure Fluctuations
21.2 Fluctuations in Time Series
21.3 Multichannel RMS
21.4 Detrended Fluctuation Analysis
21.5 Demeaned Fluctuation Analysis
21.6 Local and Global Minima and Maxima
21.7 Exercises
Part IV: Analyses of Action Potentials
22 Spikes in Full and Sparse Matrices
22.1 Spike Times as Full Matrices and as Sparse Vectors
22.2 Mean Spike Count in Spikes per Second
22.3 Peri-event Time Spike Histogram
22.4 Exercises
23 Spike Timing
23.1 Spike Rhythmicity
23.2 Spike Rhythmicity via the Frequency Domain
23.3 Cross-Neuron Spike-Time Correlations
23.4 Spike-Field Coherence
23.5 Frequency-Specific Spike-Field Coherence
23.6 Exercises
24 Spike Sorting
24.1 Spike Amplitude and Width
24.2 Spike Features via Principal Components Analysis
24.3 Spike Features via Independent Components Analysis
24.4 Clustering Spikes into Discrete Groups
24.5 Exercises
Part V: Analyses of Images
25 Magnetic Resonance Images
25.1 Importing and Plotting MRI Data
25.2 fMRI Data as a Four-Dimensional Volume
25.3 fMRI Statistics and Thresholding
25.4 Exercises
26 Image Segmentation
26.1 Threshold-Based Segmentation
26.2 Intensity-Based Segmentation
26.3 Once More, with Calcium
26.4 Defining Grids in Images
26.5 Fractals and Boxes
26.6 Exercises
27 Image Smoothing and Sharpening
27.1 Two-Dimensional Mean Filtering
27.2 Two-Dimensional Median Filter
27.3 Gaussian Kernel Smoothing
27.4 Image Filtering in the Frequency Domain
27.5 Exercises
Part VI: Modeling and Model Fitting
28 Linear Methods to Fit Models to Data
28.1 Least-Squares Fitting
28.2 Evaluating Model Fits
28.3 Polynomial Fitting Using polyfit and polyval
28.4 Example: Reaction Time and EEG Activity
28.5 Data Transformations Adjust Distributions
28.6 Exercises
29 Nonlinear Methods to Fit Models to Data
29.1 Nonlinear Model Fitting with fminsearch
29.2 Nonlinear Model Fitting: Piece-wise Regression
29.3 Nonlinear Model Fitting: Gaussian Function
29.4 Nonlinear Model Fitting: Caught in Local Minima
29.5 Discretizing and Binning Data
29.6 Exercises
30 Neural and Cognitive Simulations
30.1 Integrate-and-Fire Neurons
30.2 From Neuron to Networks
30.3 Izhikevich Neurons
30.4 Rescorla-Wagner
30.5 Exercises
31 Classification and Clustering
31.1 Neural Networks with Backpropagation Learning
31.2 K-means Clustering
31.3 Support Vector Machines
31.4 Exercises
Part VII: User Interfaces and Movies
32 Graphical User Interfaces
32.1 Basic GUIs
32.2 Getting to Know GUIDE
32.3 Writing Code in GUI Functions
32.4 Exercises
33 Movies
33.1 Waving Lines
33.2 Moving Gabor Patches
33.3 Spinning Heads
33.4 Exercises
References
Index
MATLAB for Brain and Cognitive Scientists
MATLAB for Brain and Cognitive Scientists Mike X Cohen The MIT Press Cambridge, Massachusetts London, England
© 2017 Massachusetts Institute of Technology All rights reserved. No part of this book may be reproduced in any form by any elec- tronic or mechanical means (including photocopying, recording, or information storage and retrieval) without permission in writing from the publisher. This book was set in Stone Sans and Stone Serif by Toppan Best-set Premedia Limited. Library of Congress Cataloging-in-Publication Data Names: Cohen, Mike X., 1979- author. Title: MATLAB for brain and cognitive scientists / Mike X. Cohen. Description: Cambridge, MA : MIT Press, [2017] | Includes bibliographical references and index. Identifiers: LCCN 2016033649 | ISBN 9780262035828 (h : alk. paper) Subjects: LCSH: MATLAB. | Neurosciences--Data processing. | Cognitive science--Data processing. Classification: LCC QP357.5 .C56 2017 | DDC 612.8--dc23 LC record available at https://lccn.loc.gov/2016033649 10 9 8 7 6 5 4 3 2 1
Contents Preface xv Part I: Introductions 1 1 What Is MATLAB and Why Use It? 3 1.1 “I Want to Be a Scientist; Do I Also Need to Be a Good Programmer?” 3 1.2 Octave 4 1.3 Python, Julia, C, R, SPSS, HTML, and So Forth 5 1.4 How Long Does It Take to Become a Good Programmer? 6 1.5 How to Learn How to Program 6 1.6 The Three Steps of Programming 7 1.7 How Best to Learn from This Book 8 1.8 Exercises and Their Solutions 10 1.9 Written Interviews 11 1.10 Where Is All the Code? 11 1.11 Can I Use the Code in This Book for Real Data Analyses? 11 1.12 Is This Book Right for You? 12 1.13 Are You Excited? 12 The Philosophy of Data Analysis 15 2.1 Keep It Simple 15 2.2 Stay Close to the Data 16 2.3 Understand Your Analyses 17 2.4 Use Simulations, but Trust Real Data 17 2.5 Beware the Paralysis of Analysis 18 2.6 Be Careful of Overfitting 19 2.7 Noise in Neuroscience Data 21 2.8 Avoid Circular Inference 22 2.9 Get Free Data 23 2
vi Contents 3 Do Replicable Research 25 4 3.1 Avoid Mistakes in Data Analysis 26 3.2 Have a “Large Enough” N 27 3.3 Maximize Level 1 Data Count 27 3.4 Try Different Analysis Parameters, and Trust Analytic Convergence 28 3.5 Don’t Be Afraid to Report Small or Null Effects, but Be Honest About Them 29 3.6 Do Split-Half Replication 29 3.7 Independent Replications 29 3.8 Write a Clear Methods Section 30 3.9 Make Your Analysis Code or Data Available 30 The MATLAB Program 31 4.1 The MATLAB Program Graphical User Interface 31 4.2 Layouts and Visual Preferences 32 4.3 Color-Coordinating MATLAB 35 4.4 Where Does the Code Go? 35 4.5 MATLAB Files and Formats 37 4.6 Changing Directories inside MATLAB 38 4.7 The MATLAB Path 38 4.8 Comments 40 4.9 Cells 41 4.10 Keyboard Shortcuts 41 4.11 Help Box and Reporting Variable Content 43 4.12 The Code Analyzer 45 4.13 Back Up Your Scripts, and Use Only One Version 46 4.14 MATLAB Etiquette 46 5 Variables 49 5.1 Creating and Destroying Variables 49 5.2 Whos Are My Variables? 50 5.3 Variable Naming Conventions and Tips 50 5.4 Variables for Numbers 52 5.5 Variables for Truth 54 5.6 Variables for Strings 55 5.7 Variables for Cells 56 5.8 Variables for Structures 56 5.9 The Colon Operator 57 5.10 Accessing Parts of Variables via Indexing 58 5.11 Initializing Variables 60 5.12 Soft-coding versus Hard-coding 61
分享到:
收藏