28
Dresden, 23.09.2011 Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting

Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Dresden, 23.09.2011

Introduction to Matlab

Pouyan R. Fard

Prof. Dr. Stefan J. Kiebel

Dresden, 27.04.2017

Matrices, Random Numbers, Plotting

Page 2: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 2 von XYZ

Seminar overview

2

Date Topics Projects

06.04. Intro, basic operations, First Exercise (Morse Code)

13.04. First Exercise Continued(Morse Code)

27.04. Second Exercise (Game of Life)

04.05. Second Exercise Continued (Game of Life)

05.05. Third Exercise (Drift-Diffusion Model) Project Distribution

11.05. Third Exercise Continued (Drift-Diffusion Model)

30.05. - Project Deadline (6 PM)

Page 3: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 3 von XYZ

Matrices and Vectors

3

• Thinking in a matrix way

Page 4: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 4 von XYZ

Matrices and Vectors

4

• Initializing vectors and matrices in MATLAB

Page 5: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 5 von XYZ

Matrices and Vectors

5

• Size of matrices

• Usage of spaces, commas, and semi-colons

• Dimensions must be consistent.

Page 6: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 6 von XYZ

Matrices and Vectors

6

Page 7: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 7 von XYZ

Initializing Matrices

7

• Initializing an empty matrix

• Initializing an identity matrix with size n

• Initializing a matrix whose all elements are 1 • n= number of rows , m= number of columns

• Initializing a matrix whose all elements are 0

• n= number of rows , m= number of columns

• Initializing a matrix of random integers magic(n)

• n= number of rows and columns

Page 8: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 8 von XYZ

Indexing

8

Page 9: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 9 von XYZ

• Accessing single elements in matrices

• Accessing multiple elements in matrices

Indexing

9

Page 10: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 10 von XYZ

• Accessing multiple elements in matrices

• Deleting rows or columns of a matrix

Indexing

10

Page 11: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 11 von XYZ

• Deleting rows or columns of a matrix

• Deleting one single entry in a matrix is not possible!

• Deleting one single entry is possible in vector.

Indexing

11

Page 12: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 12 von XYZ

Matrix Operations

12

Page 13: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 13 von XYZ

Matrix Operations

13

• Element-wise addition with a single-element matrix

• When dimensions don’t agree:

Page 14: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 14 von XYZ

Matrix Operations

14

• Element-wise operations

Page 15: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 15 von XYZ

Matrix Multiplication

15

• 𝐴 is a 𝑚 × 𝑛 matrix • 𝐵 is a 𝑛 × 𝑝 matrix

• (𝐴𝐵)𝑖,𝑗= 𝐴𝑖,𝑟 𝐵𝑟,𝑗𝑛𝑟=1

Page 16: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 16 von XYZ

Matrix Multiplication

16

Page 17: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 17 von XYZ

Matrix Multiplication

17

• Example 1: Application in linear algebra

Page 18: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 18 von XYZ

Matrix Multiplication

18

Example 2: Suppose you have five different products in your shop being sold with five different prices, and you sell them in five different quantities. How you can compute your revenue using matrix calculations?

Page 19: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 19 von XYZ

Example: General Linear Model

19

General Linear Models (GLMs) are widely used to localize brain activity in functional imaging. A standard GLM can be written as:

𝒀 = 𝑿𝜷 + 𝜺 Where:

𝑌1𝑌2⋮𝑌𝑛

=

1 𝑋111 𝑋21

⋯𝑋1𝑝𝑋2𝑝

⋮ ⋱ ⋮1 𝑋𝑛1 ⋯ 𝑋𝑛𝑝

×

𝛽1𝛽2⋮𝛽𝑛

+

𝜀1𝜀2⋮𝜀𝑛

BOLD Data Design Matrix Regression

Coefficients Noise

Page 20: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 20 von XYZ

Bar Plots / Histograms

20

Page 21: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 21 von XYZ

Random Numbers

21

• Uniform Distribution • Pseudo-random uniformly distributed integers

Page 22: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 22 von XYZ

Random Numbers

22

• Normal Distribution

Page 23: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 23 von XYZ

Random Numbers

23

• See MATLAB help for my for details.

Page 24: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 24 von XYZ

Random Numbers

24

• See MATLAB help for my for details.

Page 25: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 25 von XYZ

Basics of Plotting

25

Page 26: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 26 von XYZ

Subplots

26

Page 27: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 27 von XYZ

Subplots

27

Page 28: Introduction to Matlab - TU Dresden...Introduction to Matlab Pouyan R. Fard Prof. Dr. Stefan J. Kiebel Dresden, 27.04.2017 Matrices, Random Numbers, Plotting Titel der Präsentation

Titel der Präsentation Folie Nr. 28 von XYZ

References

28

• MATLAB for Psychologists (2012), Borgo, M., Soranzo, A., Grassi, M., Springer-Verlag, 2012, ISBN. 978-1-4614-2196-2. • Chapter 1. Basic Operations, pp. 1-23. • Chapter 2. Data Handling, pp. 25-46

• MATLAB for Neuroscientists, 2nd Ed: An Introduction to Scientific Computing

(2014), Wallisch, P., Lusignan, M.E., Benayoun, M.D., Baker, T.I., Dickey, A.S. and Hatsopoulos, N.G., Academic Press, ISBN. 978-0123838360. • Chapter 2-3. pp. 7-114.

• MATLAB help:

• http://www.mathworks.com/help/matlab/random-number-generation.html • http://www.mathworks.com/help/stats/random.html • http://www.mathworks.com/help/matlab/ref/subplot.html