Introduction to MATLAB

9 downloads 0 Views 7MB Size Report
Jan 29, 2015 - Duancheng Ma, Introduction to MATLAB R ... Outline Get started Variable Operation Programming I/O Graphics Toolbox ...... Communications. 1.
R Introduction to MATLAB

Duancheng Ma

Department of Microstructure Physics and Alloy Design 40237 D¨ usseldorf, Germany [email protected]

Jan. 29th , 2015

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory Basic functionality

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory Basic functionality Numerical computation: Elementary math,linear algebra, statistics, numerical calculus, Fourier analysis, optimization, ...

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory Basic functionality Numerical computation: Elementary math,linear algebra, statistics, numerical calculus, Fourier analysis, optimization, ...

Programming: Control flows, scripts and functions.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory Basic functionality Numerical computation: Elementary math,linear algebra, statistics, numerical calculus, Fourier analysis, optimization, ...

Programming: Control flows, scripts and functions.

Visualization: 2D and 3D plots.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory Basic functionality Numerical computation: Elementary math,linear algebra, statistics, numerical calculus, Fourier analysis, optimization, ...

Programming: Control flows, scripts and functions.

Visualization: 2D and 3D plots.

Applications

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory Basic functionality Numerical computation: Elementary math,linear algebra, statistics, numerical calculus, Fourier analysis, optimization, ...

Programming: Control flows, scripts and functions.

Visualization: 2D and 3D plots.

Applications Analyzing and manipulating data.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory Basic functionality Numerical computation: Elementary math,linear algebra, statistics, numerical calculus, Fourier analysis, optimization, ...

Programming: Control flows, scripts and functions.

Visualization: 2D and 3D plots.

Applications Analyzing and manipulating data. Developing algorithms.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory Basic functionality Numerical computation: Elementary math,linear algebra, statistics, numerical calculus, Fourier analysis, optimization, ...

Programming: Control flows, scripts and functions.

Visualization: 2D and 3D plots.

Applications Analyzing and manipulating data. Developing algorithms. Plotting data and functions.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory Basic functionality Numerical computation: Elementary math,linear algebra, statistics, numerical calculus, Fourier analysis, optimization, ...

Programming: Control flows, scripts and functions.

Visualization: 2D and 3D plots.

Applications Analyzing and manipulating data. Developing algorithms. Plotting data and functions. Creating GUI (Graphical User Interface).

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R can do What MATLAB

MATLAB, MAtrix LABoratory Basic functionality Numerical computation: Elementary math,linear algebra, statistics, numerical calculus, Fourier analysis, optimization, ...

Programming: Control flows, scripts and functions.

Visualization: 2D and 3D plots.

Applications Analyzing and manipulating data. Developing algorithms. Plotting data and functions. Creating GUI (Graphical User Interface). Interfacing with programs written in other languages, such as, C, C++, Java, Python, and FORTRAN. Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Installation

Go to public(\\mafs1):\Install\MathWorks\ Follow the instructions on http://msusrv4/msuwiki/Matlab (credit goes to Dr. Claudio Zambaldi) Latest version: Matlab R2014b Number of licenses: 14

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Get started

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Get started

Command Window where you type your commands and see results

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Get started

Command Window where you type your commands and see results

Workspace where you see the existing variables

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Get started

Current Folder where you see the contents

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Get started Current directory

Current Folder where you see the contents

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Get started New Script

Current Folder where you see the contents

Current directory

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

MATLAB editor

Write a script or a function The script or function file extension .m (m files)

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

MATLAB editor

Write a script or a function The script or function file extension .m (m files) file name, * means not saved

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

MATLAB editor

Write a script or a function The script or function file extension .m (m files) file name, * means not saved

comment line, starting with %

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

MATLAB editor

Write a script or a function The script or function file extension .m (m files) file name, * means not saved

comment line, starting with % command lines

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

MATLAB editor

Write a script or a function The script or function file extension .m (m files) real-time error check

file name, * means not saved

OK Warning Error

comment line, starting with % command lines

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Data types of variables No need to declare the data type of a variable.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Data types of variables No need to declare the data type of a variable. Basic data types (you will use most of the time)

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Data types of variables No need to declare the data type of a variable. Basic data types (you will use most of the time) numeric types integer and floating-point data.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Data types of variables No need to declare the data type of a variable. Basic data types (you will use most of the time) numeric types integer and floating-point data. characters and strings letters in single quotation marks, e.g. ’Hello world’

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Data types of variables No need to declare the data type of a variable. Basic data types (you will use most of the time) numeric types integer and floating-point data. characters and strings letters in single quotation marks, e.g. ’Hello world’ cell arrays contains different types and size, e.g. {’Hello’ 5 [1.1 3.0]}

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Data types of variables No need to declare the data type of a variable. Basic data types (you will use most of the time) numeric types integer and floating-point data. characters and strings letters in single quotation marks, e.g. ’Hello world’ cell arrays contains different types and size, e.g. {’Hello’ 5 [1.1 3.0]}

Other data types:

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Data types of variables No need to declare the data type of a variable. Basic data types (you will use most of the time) numeric types integer and floating-point data. characters and strings letters in single quotation marks, e.g. ’Hello world’ cell arrays contains different types and size, e.g. {’Hello’ 5 [1.1 3.0]}

Other data types: handle a reference to an object, such as, a function, or a figure

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Data types of variables No need to declare the data type of a variable. Basic data types (you will use most of the time) numeric types integer and floating-point data. characters and strings letters in single quotation marks, e.g. ’Hello world’ cell arrays contains different types and size, e.g. {’Hello’ 5 [1.1 3.0]}

Other data types: handle a reference to an object, such as, a function, or a figure structure group related data in fieldName, structName.fieldName Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Data types of variables No need to declare the data type of a variable. Basic data types (you will use most of the time) numeric types integer and floating-point data. characters and strings letters in single quotation marks, e.g. ’Hello world’ cell arrays contains different types and size, e.g. {’Hello’ 5 [1.1 3.0]}

Other data types: handle a reference to an object, such as, a function, or a figure structure group related data in fieldName, structName.fieldName ... Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating a variable Just assign a value to a name, e.g. (in command window) >> a=1 a= 1

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating a variable Just assign a value to a name, e.g. (in command window) >> a=1 a= 1 Variable name: must start with a letter,

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating a variable Just assign a value to a name, e.g. (in command window) >> a=1 a= 1 Variable name: must start with a letter, after that, letters, numbers and

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

(underscore), no others,

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating a variable Just assign a value to a name, e.g. (in command window) >> a=1 a= 1 Variable name: must start with a letter, after that, letters, numbers and (underscore), no others, case sensitive, e.g. a is different from A.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating a variable Just assign a value to a name, e.g. (in command window) >> a=1 a= 1 Variable name: must start with a letter, after that, letters, numbers and (underscore), no others, case sensitive, e.g. a is different from A.

Avoid using the following names, as they are built-in variables i and j are imaginary unit Inf is positive infinity, -Inf is negative infinity pi is π, ratio of circle’s circumference to its diameter NaN means “Not a Number” ans the last value which is not assigned, like on a calculator Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating scalar variables Explicitly assigned: >> a=1 a= 1 Function of existing variables and/or explicit values: >> b=1+a b= 2

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating scalar variables Explicitly assigned: >> a=1 a= 1 Function of existing variables and/or explicit values: >> b=1+a b= 2 End the command line with a semicolon to suppress output in the command window: >> b=1+a; >>

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating vector variables Row vector: in brackets, values are separated by comma or space. >> r=[1,2,3,4]; >> r=[1 2 3 4] r= 1234 Column vector: in brackets, values are separated by semicolon. >> c=[1;2;3;4] c= 1 2 3 4 Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating matrix variables Similar to creating vectors, use semicolon to start a new row. >> A=[1 2;3 4] A= 1 2 3 4

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating matrix variables Similar to creating vectors, use semicolon to start a new row. >> A=[1 2;3 4] A= 1 2 3 4 Putting vectors and/or matrices together >> a=[1 2]; >> b=[3 4];

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating matrix variables Similar to creating vectors, use semicolon to start a new row. >> A=[1 2;3 4] A= 1 2 3 4 Putting vectors and/or matrices together >> a=[1 2]; >> b=[3 4]; >> A=[a;b] A= 1 2 3 4

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating matrix variables Similar to creating vectors, use semicolon to start a new row. >> A=[1 2;3 4] A= 1 2 3 4 Putting vectors and/or matrices together >> a=[1 2]; >> b=[3 4]; >> A=[a;b] A= 1 2 3 4 >> r=[a b] r= 1234 Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Automatically creating vector and matrix variables Special matrices, zeros, ones, and eye

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Automatically creating vector and matrix variables Special matrices, zeros, ones, and eye >> A=zeros(3,2) A= 0 0 0 0 0 0

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Automatically creating vector and matrix variables Special matrices, zeros, ones, and eye >> A=zeros(3,2) >> A=ones(2,3) A= A= 0 0 1 1 1 0 0 1 1 1 0 0

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Automatically creating vector and matrix variables Special matrices, zeros, ones, and eye >> A=zeros(3,2) >> A=ones(2,3) A= A= 0 0 1 1 1 0 0 1 1 1 0 0

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

>> A=eye(3,3) A= 1 0 0 0 1 0 0 0 1

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Automatically creating vector and matrix variables Special matrices, zeros, ones, and eye >> A=zeros(3,2) >> A=ones(2,3) A= A= 0 0 1 1 1 0 0 1 1 1 0 0

>> A=eye(3,3) A= 1 0 0 0 1 0 0 0 1

Random numbers between 0 and 1, rand >> A=rand(1,4) A= 0.9134 0.2785 0.9649 0.1576

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Automatically creating vector and matrix variables Special matrices, zeros, ones, and eye >> A=zeros(3,2) >> A=ones(2,3) A= A= 0 0 1 1 1 0 0 1 1 1 0 0

>> A=eye(3,3) A= 1 0 0 0 1 0 0 0 1

Random numbers between 0 and 1, rand >> A=rand(1,4) A= 0.9134 0.2785 0.9649 0.1576 linear spaced values, : (colon)

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Automatically creating vector and matrix variables Special matrices, zeros, ones, and eye >> A=zeros(3,2) >> A=ones(2,3) A= A= 0 0 1 1 1 0 0 1 1 1 0 0

>> A=eye(3,3) A= 1 0 0 0 1 0 0 0 1

Random numbers between 0 and 1, rand >> A=rand(1,4) A= 0.9134 0.2785 0.9649 0.1576 linear spaced values, : (colon) >> a=1:1:4 a= 1 2 3 4 Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Automatically creating vector and matrix variables Special matrices, zeros, ones, and eye >> A=zeros(3,2) >> A=ones(2,3) A= A= 0 0 1 1 1 0 0 1 1 1 0 0

>> A=eye(3,3) A= 1 0 0 0 1 0 0 0 1

Random numbers between 0 and 1, rand >> A=rand(1,4) A= 0.9134 0.2785 0.9649 0.1576 linear spaced values, : (colon) >> a=1:1:4 a= 1 2 3 4 Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

>> a=1:4 a= 1 2 3 Duancheng Ma,

4

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating character and string variables Similar to creating numeric variables, assign a value to a name, must be in single quotation marks >> s=’Hello world’ s= Hello world

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating character and string variables Similar to creating numeric variables, assign a value to a name, must be in single quotation marks >> s=’Hello world’ s= Hello world Use sprintf(format,variable),

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating character and string variables Similar to creating numeric variables, assign a value to a name, must be in single quotation marks >> s=’Hello world’ s= Hello world Use sprintf(format,variable), >> s=sprintf(’Base of the natural logarithm is %f’,exp(1)) s= Base of the natural logarithm is 2.718282

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Creating character and string variables Similar to creating numeric variables, assign a value to a name, must be in single quotation marks >> s=’Hello world’ s= Hello world Use sprintf(format,variable), >> s=sprintf(’Base of the natural logarithm is %f’,exp(1)) s= Base of the natural logarithm is 2.718282 >> s=sprintf(’In Excel the index starts with %s%d’,65,1) s= In Excel the index starts with A1 Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Save and Load variables

>> save saved file a b save variables a b in saved file.mat in the current folder

>> load saved file load variables stored in saved file.mat stored variables a and b appear in the workspace

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Operations on scalars Arithmetic operations: + Exponentiation:

-

*

/



Parentheses for complicated expressions: ( ) Built-in functions: e.g. (a is a scalar) √

a >> sqrt(a) ln (a) >> log(a) log10 (a) >> log10(a) exp (a) >> exp(a) cos (a) >> cos(a) % a in radians >> cosd(a) % a in degree ... ... all you can think of, but be careful, check the documentation to make sure Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Transpose vectors and matrices Transpose: transpose(a), .0 , or >> a=[1 2 3]; >> transpose(a) ans= 1 2 3

0

>> a.0 ans= 1 2 3

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

>> a0 ans= 1 2 3

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Transpose vectors and matrices Transpose: transpose(a), .0 , or >> a=[1 2 3];

0

>> transpose(a) >> a.0 >> a0 ans= ans= ans= 1 1 1 2 2 2 3 3 3 Transpose complex numbers, be careful with 0 , it gives Hermitian-transpose >> a=[1 2 3+i]; >> transpose(a) ans= 1 2 3+i

>> a.0 ans= 1 2 3+i

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

>> a0 ans= 1 2 3-i Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Operations on vectors and matrices Standard operation and element-wise operation >> a=[a1 a2]; >> b=[b1 b2];

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Operations on vectors and matrices Standard operation and element-wise operation >> a=[a1 a2]; >> b=[b1 b2]; Standard >> a*b >> a*b0

    ⇒ a1 a2 · b1  b2 , wrong   b1 ⇒ a1 a2 · =a1·b1+a2·b2, dot product b2

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Operations on vectors and matrices Standard operation and element-wise operation >> a=[a1 a2]; >> b=[b1 b2]; Standard >> a*b

    ⇒ a1 a2 · b1  b2 , wrong   b1 ⇒ a1 a2 · =a1·b1+a2·b2, dot product >> a*b0 b2 Element-wise, use  dot .  >> a.*b ⇒ a1 · b1 a2 · b2 >> a./b ⇒ a1/b1 a2/b2  >> a.∧ 2 ⇒ a12 a22

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Operations on vectors and matrices Standard operation and element-wise operation >> a=[a1 a2]; >> b=[b1 b2]; Standard >> a*b

    ⇒ a1 a2 · b1  b2 , wrong   b1 ⇒ a1 a2 · =a1·b1+a2·b2, dot product >> a*b0 b2 Element-wise, use  dot .  >> a.*b ⇒ a1 · b1 a2 · b2 >> a./b ⇒ a1/b1 a2/b2  >> a.∧ 2 ⇒ a12 a22

Built-in functions, if the function works for scalars, then it operates on vectors and matrices by element-wise >> sqrt(A) >> sqrtm(A)

⇒ square root of each element ⇒ square root of the matrix

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

inverse and left side division

      A11 A12 A13 x1 b1 A21 A22 A23  · x2  = b2  A31 A32 A33 x3 b3

  A11 A12 A13 A = A21 A22 A23  A31 A32 A33

  x1 x = x2  x3

  b1 b = b2  b3

Use inverse of matrix A:

Use left side division:

>> x=inv(A)*b

>> x=A\b

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Relational and logical operations Relational operation less than < greater than > less or equal = equal == not equal ∼= Logical operation and & && (short circuit) or | || (short circuit) exclusive or xor not ∼ all all any any Boolean values: zero is false, non-zero is true. Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Relational and logical operations

>> a=[3 2 8 5]; >> b=[7 1 4 5]; >> a>b ans= 0 1 1 0 >> a==b ans= 0 0 0 1

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

>> a=[2 0 3 0]; >> b=[4 1 0 0]; >> a&b ans= 1 0 0 0 >> a|b ans= 1 1 1 0

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Indexing the vectors

Indices must be real positive non-zero integers, e.g. 1, 2, 3, 4,...

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Indexing the vectors

Indices must be real positive non-zero integers, e.g. 1, 2, 3, 4,... Accessing individual elements of a vector, a(n) returns nth element of the vector a. >> a=[1 2 3 4 5 6 7];

>> a(1) ans= 1

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Indexing the vectors

Indices must be real positive non-zero integers, e.g. 1, 2, 3, 4,... Accessing individual elements of a vector, a(n) returns nth element of the vector a. >> a=[1 2 3 4 5 6 7];

>> a(1) ans= 1

use linear spaced value >> a(2:1:4) ans= 2 3 4

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Indexing the vectors

Indices must be real positive non-zero integers, e.g. 1, 2, 3, 4,... Accessing individual elements of a vector, a(n) returns nth element of the vector a. >> a=[1 2 3 4 5 6 7];

>> a(1) ans= 1

use linear spaced value >> a(2:1:4) ans= 2 3 4

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

use another vector >> a([2 4]) ans= 2 4

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Indexing the matrices >> A=[1 2 3;4 5 6;7 8 9] A= 1 2 3 4 5 6 7 8 9

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Indexing the matrices >> A=[1 2 3;4 5 6;7 8 9] A= 1 2 3 4 5 6 7 8 9 A(n,m) returns element of the matrix A on nth row and mth column. >> A(2,3) >> A(2,2:1:3) >> A(:,2:1:3) ans= ans= ans= 6 5 6 2 3 5 6 8 9

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Indexing the matrices >> A=[1 2 3;4 5 6;7 8 9] A= 1 2 3 4 5 6 7 8 9 A(n,m) returns element of the matrix A on nth row and mth column. >> A(2,3) >> A(2,2:1:3) >> A(:,2:1:3) ans= ans= ans= 6 5 6 2 3 5 6 8 9 th A(n) returns n element of the matrix A. >> A(2) >> A(1:1:3) ans= ans= 4 1 4 7 Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Command sort to sort vectors and matrices >> a=[2 4 1 5 6 3] a= 2 4 1 5

6

3

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Command sort to sort vectors and matrices >> a=[2 4 1 5 6 3] a= 2 4 1 5

6

3

Sorting the vector a in the ascending order, >> sort(a) ans= 1 2 3 4 5 6

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Command sort to sort vectors and matrices >> a=[2 4 1 5 6 3] a= 2 4 1 5

6

3

Sorting the vector a in the ascending order, >> sort(a) ans= 1 2 3 4 5 6 Getting the arrangement, i.e. indices in the sorted vector, >> [as, as ix]=sort(a) as= 1 2 3 4 5 6 as ix= 3 1 6 2 4 5

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Command sort to sort vectors and matrices >> a=[2 4 1 5 6 3] a= 2 4 1 5

6

3

Sorting the vector a in the ascending order, >> sort(a) ans= 1 2 3 4 5 6 Getting the arrangement, i.e. indices in the sorted vector, >> [as, as ix]=sort(a) as= 1 2 3 4 5 6 as ix= 3 1 6 2 4 5 Sorting the vector a in the descending order, sort(a,’descend’), Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Command sort to sort vectors and matrices >> a=[2 4 1 5 6 3] a= 2 4 1 5

6

3

Sorting the vector a in the ascending order, >> sort(a) ans= 1 2 3 4 5 6 Getting the arrangement, i.e. indices in the sorted vector, >> [as, as ix]=sort(a) as= 1 2 3 4 5 6 as ix= 3 1 6 2 4 5 Sorting the vector a in the descending order, sort(a,’descend’), For matrices, sort is to sort each column. Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Command find >> a=[2 4 1 5 6 3 1] a= 2 4 1 5

6

3

1

Finding the value 1 in vector a, >> find(a==1) ans= 3 7 =⇒the 3rd and 7th element in vector a are 1.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Command find >> a=[2 4 1 5 6 3 1] a= 2 4 1 5

6

3

1

Finding the value 1 in vector a, >> find(a==1) ans= 3 7 =⇒the 3rd and 7th element in vector a are 1. Finding the value 4 or 5 in vector a, >> find(a==4 | a==5) ans= 2 4 =⇒the 2nd and 4th element in vector a is 4 or 5.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Command find >> A=[5 4 1 ;2 6 3] A= 5 4 1 2 6 3 Finding the value 4 in matrix A, >> find(A==4) ans= 3 =⇒the 3rd element in matrix A is 4.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Mathematical operations Relational and Logical operations Vectors and matrices manipulations

Command find >> A=[5 4 1 ;2 6 3] A= 5 4 1 2 6 3 Finding the value 4 in matrix A, >> find(A==4) ans= 3 =⇒the 3rd element in matrix A is 4. >> [r, c]=find(A==4) r= 1 =⇒on 1st row c= 2 =⇒on 2rd column. Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows R MATLAB

1

What

can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows R MATLAB

1

What

can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

Starting MATLAB editor Current directory

Current Folder where you see the contents

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

Starting MATLAB editor New Script

Current Folder where you see the contents

Current directory

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

MATLAB script

A script is a collection of commands which executed in sequence real-time error check

file name, * means not saved

OK Warning Error

comment line, starting with % command lines

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

MATLAB script

A script is a collection of commands which executed in sequence real-time error check

file name, * means not saved Press to run

OK Warning Error

?

comment line, starting with % command lines

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

MATLAB function

A function can be called in a script, another function, or in the Command windows. Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

MATLAB function

it starts with function

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

MATLAB function

declare the function

[output arg1,output arg2,...]=function name(input arg1,input arg2,...) Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

MATLAB function

file name function name

The file name and the function name should be the same. Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

MATLAB function

help contents

>> help data =⇒ help contents appear in command window. Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

MATLAB function

code

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

Call MATLAB function

If you want to call your MATLAB functions, make sure, The function file is in the Current directory.

OR The folder where the function file is is in the search path. Home tab⇒Environment section⇒Set Path

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

Set Path Set Path

Current Folder where you see the contents

Current directory

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows R MATLAB

1

What

can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

Control flow: if/elseif/else

if conditional command end

if conditional command else conditional command end

if conditional command elseif conditional command else conditional command end

conditional is evaluated to be true or false, execute when true,

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

Control flow: for and while loop for Index=initVal:step:endVal command end

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

while conditional command end

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

Control flow: for and while loop for Index=initVal:step:endVal command end

while conditional command end

e.g. to calculate 5! i.e. 1×2×3×4×5=120

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

Control flow: for and while loop for Index=initVal:step:endVal command end

while conditional command end

e.g. to calculate 5! i.e. 1×2×3×4×5=120 a=1; for n=1:1:5 a=a*n; end

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing Scripts and Functions Control flows

Control flow: for and while loop for Index=initVal:step:endVal command end

while conditional command end

e.g. to calculate 5! i.e. 1×2×3×4×5=120 a=1; for n=1:1:5 a=a*n; end

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

a=1;n=1; while n class(c) =⇒ check data type of c ans= cell

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Reading Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

>> class(c) =⇒ check data type of c ans= cell >> size(c) ans= 1 2 =⇒ c has one row and two columns

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Reading Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

>> class(c) =⇒ check data type of c ans= cell >> size(c) ans= 1 2 =⇒ c has one row and two columns >> c(1) =⇒ use () to access the 1st element in c

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Reading Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

>> class(c) ans= cell >> size(c) ans= 1 2 >> c(1) ans= [12x1 int32]

=⇒ check data type of c

=⇒ c has one row and two columns =⇒ use () to access the 1st element in c =⇒ the 1st element in c is a vector, it has 12 rows and 1 column, its data type is 32-bit signed integer.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Reading Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

>> class(c) ans= cell >> size(c) ans= 1 2 >> c(1) ans= [12x1 int32] >> c{1} ans= 1 2 .. . 11 12

=⇒ check data type of c

=⇒ c has one row and two columns =⇒ use () to access the 1st element in c =⇒ the 1st element in c is a vector, it has 12 rows and 1 column, its data type is 32-bit signed integer. =⇒ use {} to access the 1st element in c

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Writing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Writing Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144 Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Writing Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

fid=fopen(’data.txt’,’w’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

=⇒ open the file to write - permission, ’w’ is to write - file name, in single quotation marks - file ID

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Writing Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

fid=fopen(’data.txt’,’w’);

=⇒ open the file to write - permission, ’w’ is to write - file name, in single quotation marks - file ID

X=1:1:12=⇒ prepare X data, linear spaced Y=X.∧ 2 =⇒ prepare Y data, element-wise operation

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Writing Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

fid=fopen(’data.txt’,’w’);

=⇒ open the file to write - permission, ’w’ is to write - file name, in single quotation marks - file ID

X=1:1:12=⇒ prepare X data, linear spaced Y=X.∧ 2 =⇒ prepare Y data, element-wise operation fprintf(fid,’Y=X.∧ 2\n’); =⇒ write the first line

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Writing Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

fid=fopen(’data.txt’,’w’);

=⇒ open the file to write - permission, ’w’ is to write - file name, in single quotation marks - file ID

X=1:1:12=⇒ prepare X data, linear spaced Y=X.∧ 2 =⇒ prepare Y data, element-wise operation fprintf(fid,’Y=X.∧ 2\n’); =⇒ write the first line

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

-format, in single quotation marks -file ID \n is to switch to a new line

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Writing Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

fid=fopen(’data.txt’,’w’);

=⇒ open the file to write - permission, ’w’ is to write - file name, in single quotation marks - file ID

X=1:1:12=⇒ prepare X data, linear spaced Y=X.∧ 2 =⇒ prepare Y data, element-wise operation fprintf(fid,’Y=X.∧ 2\n’); =⇒ write the first line -format, in single quotation marks -file ID \n is to switch to a new line

fprintf(fid,’X Y\n’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

=⇒ write the second line

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Writing Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

fid=fopen(’data.txt’,’w’);

=⇒ open the file to write - permission, ’w’ is to write - file name, in single quotation marks - file ID

X=1:1:12=⇒ prepare X data, linear spaced Y=X.∧ 2 =⇒ prepare Y data, element-wise operation fprintf(fid,’Y=X.∧ 2\n’); =⇒ write the first line -format, in single quotation marks -file ID \n is to switch to a new line

fprintf(fid,’X Y\n’);

=⇒ write the second line

for n=1:1:length(X) fprintf(fid,’%d %d\n’,X(n),Y(n)); end

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Writing Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

fid=fopen(’data.txt’,’w’);

=⇒ open the file to write - permission, ’w’ is to write - file name, in single quotation marks - file ID

X=1:1:12=⇒ prepare X data, linear spaced Y=X.∧ 2 =⇒ prepare Y data, element-wise operation fprintf(fid,’Y=X.∧ 2\n’); =⇒ write the first line -format, in single quotation marks -file ID \n is to switch to a new line

fprintf(fid,’X Y\n’);

=⇒ write the second line

for n=1:1:length(X) fprintf(fid,’%d %d\n’,X(n),Y(n)); end

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

data.txt Writing Y=X∧ 2 X Y 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 11 121 12 144

fid=fopen(’data.txt’,’w’);

=⇒ open the file to write - permission, ’w’ is to write - file name, in single quotation marks - file ID

X=1:1:12=⇒ prepare X data, linear spaced Y=X.∧ 2 =⇒ prepare Y data, element-wise operation fprintf(fid,’Y=X.∧ 2\n’); =⇒ write the first line -format, in single quotation marks -file ID \n is to switch to a new line

fprintf(fid,’X Y\n’);

=⇒ write the second line

for n=1:1:length(X) fprintf(fid,’%d %d\n’,X(n),Y(n)); end fclose(fid);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing R Reading and Writing text files Reading and Writing Microsoft Excel files

R Excel files Reading and Writing Microsoft

data=xlsread(file name,sheet name,data range) data, numeric type, file name and sheet name, string, e.g. ’data.xlsx’ and ’Sheet1’, data range, string, e.g. ’A1:C10’.

xlswrite(file name,M,sheet name,data range) M, a matrix.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R graphics overview MATLAB

2D plots Line graphs Bar graphs Area graphs Direction graphs Radial graphs Scatter graphs

3D plots Line Graphs Mesh Graphs and Bar Graphs Area Graphs and Constructive Objects Surface Graphs Direction Graphs Volumetric Graphs

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R graphics overview MATLAB

2D plots Line graphs: plot and plotyy Bar graphs: bar and hist Area graphs Direction graphs Radial graphs Scatter graphs

3D plots Line Graphs Mesh Graphs and Bar Graphs Area Graphs and Constructive Objects Surface Graphs: surf Direction Graphs Volumetric Graphs

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2;

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; >>plot(x,y);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; >>plot(x,y); >>plot(x,y,’Color’,’red’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; >>plot(x,y); >>plot(x,y,’Color’,’red’); >>plot(x,y,’Color’,’red’,’Marker’,’o’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; >>plot(x,y); >>plot(x,y,’Color’,’red’); >>plot(x,y,’Color’,’red’,’Marker’,’o’); >>xlabel(’x’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; >>plot(x,y); >>plot(x,y,’Color’,’red’); >>plot(x,y,’Color’,’red’,’Marker’,’o’); >>xlabel(’x’); >>ylabel(’y’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; >>plot(x,y); >>plot(x,y,’Color’,’red’); >>plot(x,y,’Color’,’red’,’Marker’,’o’); >>xlabel(’x’); >>ylabel(’y’); >>y1=x.∧ 3;

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; >>plot(x,y); >>plot(x,y,’Color’,’red’); >>plot(x,y,’Color’,’red’,’Marker’,’o’); >>xlabel(’x’); >>ylabel(’y’); >>y1=x.∧ 3; >>hold on;=⇒new plot on existing plot

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; >>plot(x,y); >>plot(x,y,’Color’,’red’); >>plot(x,y,’Color’,’red’,’Marker’,’o’); >>xlabel(’x’); >>ylabel(’y’); >>y1=x.∧ 3; >>hold on;=⇒new plot on existing plot >>plot(x,y1,’Color’,’black’,’Marker’,’s’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; >>plot(x,y); >>plot(x,y,’Color’,’red’); >>plot(x,y,’Color’,’red’,’Marker’,’o’); >>xlabel(’x’); >>ylabel(’y’); >>y1=x.∧ 3; >>hold on;=⇒new plot on existing plot >>plot(x,y1,’Color’,’black’,’Marker’,’s’); >>legend({’x∧ 2’ ’x∧ 3’});

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; >>plot(x,y); >>plot(x,y,’Color’,’red’); >>plot(x,y,’Color’,’red’,’Marker’,’o’); >>xlabel(’x’); >>ylabel(’y’); >>y1=x.∧ 3; >>hold on;=⇒new plot on existing plot >>plot(x,y1,’Color’,’black’,’Marker’,’s’); >>legend({’x∧ 2’ ’x∧ 3’}); >>legend({’x∧ 2’ ’x∧ 3’},’Location’,’NorthWest’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plot >>x=1:1:12; >>y=x.∧ 2; 1800

>>plot(x,y);

x2 x3

1600

>>plot(x,y,’Color’,’red’);

1400

>>plot(x,y,’Color’,’red’,’Marker’,’o’);

1200

1000

y

>>xlabel(’x’); >>ylabel(’y’); >>y1=x.∧ 3;

800

600

400

>>hold on;=⇒new plot on existing plot >>plot(x,y1,’Color’,’black’,’Marker’,’s’);

200

0 0

2

4

6

8

10

x

>>legend({’x∧ 2’ ’x∧ 3’}); >>legend({’x∧ 2’ ’x∧ 3’},’Location’,’NorthWest’); >>print(’-dpdf’,’-r1000’,’plot.pdf’)=⇒print the figure to pdf

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

12

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plotyy (y on both left and right) >>x=1:1:12; >>y=x.∧ 2; >>y1=x.∧ 3;

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Line plot: plotyy (y on both left and right) >>x=1:1:12; >>y=x.∧ 2; >>y1=x.∧ 3; >>[ax,h1,h2]=plotyy(x,y1,x,y); get two axes handles (ax) and two graphic objects handles (h1 and h2)

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are in these handles? >>get(h1)=⇒properties of the blue curve

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are in these handles? >>get(h1)=⇒properties of the blue curve

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are in these handles? >>get(h1)=⇒properties of the blue curve

6 property

6 value

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are in these handles? >>get(h1)=⇒properties of the blue curve >>get(h1,’Marker’) >>ans = none

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are in these handles? >>get(h1)=⇒properties of the blue curve >>get(h1,’Marker’) >>ans = none >>set(h1,’Marker’,’o’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are in these handles? >>get(h1)=⇒properties of the blue curve >>get(h1,’Marker’) >>ans = none >>set(h1,’Marker’,’o’); >>set(h1,’LineStyle’,’–’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are in these handles? >>get(h1)=⇒properties of the blue curve >>get(h1,’Marker’) >>ans = none >>set(h1,’Marker’,’o’); >>set(h1,’LineStyle’,’–’); >>set(h1,’Color’,’black’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are in these handles? >>get(h1)=⇒properties of the blue curve >>get(h1,’Marker’) >>ans = none >>set(h1,’Marker’,’o’); >>set(h1,’LineStyle’,’–’); >>set(h1,’Color’,’black’); >>set(ax(1),’YColor’,’black’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: bar

>>a=rand(1,5); =⇒get 5 random numbers

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: bar

>>a=rand(1,5); =⇒get 5 random numbers >>h=bar(a); get the graphic object handle (h)

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: bar

>>a=rand(1,5); =⇒get 5 random numbers >>h=bar(a); get the graphic object handle (h) >>set(h,’FaceColor’,’white’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: bar

>>a=rand(1,5); =⇒get 5 random numbers >>h=bar(a); get the graphic object handle (h) >>set(h,’FaceColor’,’white’); >>set(h,’EdgeColor’,’blue’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: bar

>>a=rand(1,5); =⇒get 5 random numbers >>h=bar(a); get the graphic object handle (h) >>set(h,’FaceColor’,’white’); >>set(h,’EdgeColor’,’blue’); >>XTL={’1st’ ’2nd’ ’3rd’ ’4th’ ’5th’}; >>set(gca,’XTickLabel’,XTL); get the current axes handle (gca)

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: hist for probability and statistics >>a=randn(1,1e4); =⇒get 104 random numbers following normal distribution

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: hist for probability and statistics >>a=randn(1,1e4); =⇒get 104 random numbers following normal distribution >>subplot(1,2,1);=⇒ multiple plots

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: hist for probability and statistics >>a=randn(1,1e4); =⇒get 104 random numbers following normal distribution >>subplot(1,2,1);=⇒ multiple plots >>hist(a);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: hist for probability and statistics >>a=randn(1,1e4); =⇒get 104 random numbers following normal distribution >>subplot(1,2,1);=⇒ multiple plots >>hist(a); >>hist(a,100);=⇒ 100 bins

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: hist for probability and statistics >>a=randn(1,1e4); =⇒get 104 random numbers following normal distribution >>subplot(1,2,1);=⇒ multiple plots >>hist(a); >>hist(a,100);=⇒ 100 bins >>subplot(1,2,2);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: hist for probability and statistics >>a=randn(1,1e4); =⇒get 104 random numbers following normal distribution >>subplot(1,2,1);=⇒ multiple plots >>hist(a); >>hist(a,100);=⇒ 100 bins >>subplot(1,2,2); >>[c,x]=hist(a,100);=⇒ no figure is plotted c, counts, x, center of bins.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Bar plot: hist for probability and statistics >>a=randn(1,1e4); =⇒get 104 random numbers following normal distribution >>subplot(1,2,1);=⇒ multiple plots >>hist(a); >>hist(a,100);=⇒ 100 bins >>subplot(1,2,2); >>[c,x]=hist(a,100);=⇒ no figure is plotted c, counts, x, center of bins. >>plot(x,c);=⇒ line graph

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Surface plot: surf

>>x=0:0.01:2*pi; >>y=0:0.01:2*pi; >>for n=1:1:length(x) >> >> >>

for m=1:1:length(y) z(n,m)=cos(x(n))+sin(y(m)); end

>>end=⇒get z=cos(x)+sin(y)

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Surface plot: surf

>>x=0:0.01:2*pi; >>y=0:0.01:2*pi; >>for n=1:1:length(x) >> >> >>

for m=1:1:length(y) z(n,m)=cos(x(n))+sin(y(m)); end

>>end=⇒get z=cos(x)+sin(y) >>hs=surf(x,y,z);=⇒ get surface handle (hs)

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Surface plot: surf

>>x=0:0.01:2*pi; >>y=0:0.01:2*pi; >>for n=1:1:length(x) >> >> >>

for m=1:1:length(y) z(n,m)=cos(x(n))+sin(y(m)); end

>>end=⇒get z=cos(x)+sin(y) >>hs=surf(x,y,z);=⇒ get surface handle (hs) >>set(hs,’LineStyle’,’none’);

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Surface plot: surf

>>x=0:0.01:2*pi; >>y=0:0.01:2*pi; >>for n=1:1:length(x) >> >> >>

for m=1:1:length(y) z(n,m)=cos(x(n))+sin(y(m)); end

>>end=⇒get z=cos(x)+sin(y) >>hs=surf(x,y,z);=⇒ get surface handle (hs) >>set(hs,’LineStyle’,’none’); >>colorbar

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Surface plot: surf

>>x=0:0.01:2*pi; >>y=0:0.01:2*pi; >>for n=1:1:length(x) >>

for m=1:1:length(y)

>> >>

z(n,m)=cos(x(n))+sin(y(m)); end

>>end=⇒get z=cos(x)+sin(y) >>hs=surf(x,y,z);=⇒ get surface handle (hs) >>set(hs,’LineStyle’,’none’); >>colorbar >>light

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Surface plot: surf

>>x=0:0.01:2*pi; >>y=0:0.01:2*pi; >>for n=1:1:length(x) >>

for m=1:1:length(y)

>> >>

z(n,m)=cos(x(n))+sin(y(m)); end

>>end=⇒get z=cos(x)+sin(y) >>hs=surf(x,y,z);=⇒ get surface handle (hs) >>set(hs,’LineStyle’,’none’); >>colorbar >>light >>colormap hsv

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are the toolboxes?

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are the toolboxes?

Toolboxes are additions to MATLAB, which means you need to pay extra for them.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are the toolboxes?

Toolboxes are additions to MATLAB, which means you need to pay extra for them. Each toolbox is for a specific purpose,

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

What are the toolboxes?

Toolboxes are additions to MATLAB, which means you need to pay extra for them. Each toolbox is for a specific purpose, Each toolbox contains a collection (library) of functions, and usually a graphical user interface.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Where are the toolboxes?

Current Folder where you see the contents

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Where are the toolboxes? APPS

Current Folder where you see the contents

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Where are the toolboxes?

Current Folder where you see the contents

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Where are the toolboxes? list of toolboxes

Current Folder where you see the contents

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Available licensed toolboxes number of licenses Mathematics, statistics and optimization Optimization Global Optimization Neural Network Partial Differential Equation Statistics Curve Fitting Symbolic Math Image Processing and Computer Vision Image Processing Signal Processing and Communications Signal Processing DSP System Communications Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

3 N/A N/A 1 2 3 1 4 1 1 1 R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Available licensed toolboxes number of licenses Mathematics, statistics and optimization Optimization Global Optimization Neural Network Partial Differential Equation Statistics Curve Fitting Symbolic Math Image Processing and Computer Vision Image Processing Signal Processing and Communications Signal Processing DSP System Communications Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

3 N/A N/A 1 2 3 1 4 1 1 1 R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Click Curve Fitting icon Curve Fitting

Current Folder where you see the contents

Command Window where you type your commands and see results

in the current folder

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Workspace where you see the existing variables

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Curve fitting toolbox graphic interface

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Curve fitting toolbox graphic interface

Data for fitting

must be in workspace

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Fitting function

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Curve fitting toolbox graphic interface

Data for fitting

Fitting function

must be in workspace

Fitted coefficients Goodness‐of‐fit

Figure plotting fitting data and function

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Curve fitting toolbox graphic interface

Data for fitting x=1:1:12; y=x.∧ 2;

Fitting function

must be in workspace

f(x)=p1*x+p2

Fitted coefficients Goodness‐of‐fit Goodness of fit SSE=1335 P SSE= i (yi − f (xi ))2

Figure plotting fitting data and function

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Curve fitting toolbox graphic interface

Data for fitting x=1:1:12; y=x.∧ 2;

must be in workspace

Fitting function

f(x)=p1*x∧ 3+p2*x∧ 2+p3*x+p4

Fitted coefficients Goodness‐of‐fit Goodness of fit SSE=1.314e-27 P SSE= i (yi − f (xi ))2

Figure plotting fitting data and function

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Curve fitting toolbox graphic interface FileGenerateCode

Data for fitting

Fitting function

must be in workspace

Fitted coefficients Goodness‐of‐fit

Figure plotting fitting data and function

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Generated code

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Generated code

function [fitresult,gof]=createFit(x,y)

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

-

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Generated code

function [fitresult,gof]=createFit(x,y)

-

fitresult: Curve fit object data type gof: structure data type

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Generated code

function [fitresult,gof]=createFit(x,y)

-

fitresult: Curve fit object data type gof: structure data type >>coeffvalues(fitresult) =⇒get the fitted coefficients type “help cfit” in command window for a complete list of methods

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Generated code

function [fitresult,gof]=createFit(x,y)

-

fitresult: Curve fit object data type gof: structure data type >>coeffvalues(fitresult) =⇒get the fitted coefficients type “help cfit” in command window for a complete list of methods >>gof.sse =⇒get SSE of goodness of fit

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

1

R What MATLAB can do, Installation and Get started

2

Data type and Creating variables

3

Operations and Manipulations Mathematical operations Relational and Logical operations Vectors and matrices manipulations

4

Programming Scripts and Functions Control flows

5

File I/O (Input and Output) Reading and Writing text files R Reading and Writing Microsoft Excel files

6

Graphics

7

Toolbox

8

Before closing

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Before closing R MATLAB documentation is very well written, and you can learn most of the functions by yourself.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Before closing R MATLAB documentation is very well written, and you can learn most of the functions by yourself. R The library of the built-in functions of MATLAB is very large, which meets most of your requirements.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Before closing R MATLAB documentation is very well written, and you can learn most of the functions by yourself. R The library of the built-in functions of MATLAB is very large, which meets most of your requirements. In case what you need is missing in the built-in function library, try your luck at http://mathworks.com/matlabcentral/fileexchange/.

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Before closing R MATLAB documentation is very well written, and you can learn most of the functions by yourself. R The library of the built-in functions of MATLAB is very large, which meets most of your requirements. In case what you need is missing in the built-in function library, try your luck at http://mathworks.com/matlabcentral/fileexchange/. R MATLAB now has the capability of handling symbolic math R through Symbolic Math Toolbox . It seems, however, it is R

not as powerful as Mathematica (http://en.wikipedia.org/wiki/List of computer algebra systems).

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Before closing R MATLAB documentation is very well written, and you can learn most of the functions by yourself. R The library of the built-in functions of MATLAB is very large, which meets most of your requirements. In case what you need is missing in the built-in function library, try your luck at http://mathworks.com/matlabcentral/fileexchange/. R MATLAB now has the capability of handling symbolic math R through Symbolic Math Toolbox . It seems, however, it is R

not as powerful as Mathematica (http://en.wikipedia.org/wiki/List of computer algebra systems). R “An Introduction to MATLAB Programming and Numerical Methods for Engineers” (2015) by Timmy Siauw and Alexandre Bayen, http://www.sciencedirect.com/science/book/9780124202283 Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

R Open sources: alternatives to MATLAB

Some open sources for scientific computing: IPython http://ipython.org/notebook.html Sage http://www.sagemath.org/ https://cloud.sagemath.com/ Pyzo http://www.pyzo.org/index.html Julia http://julialang.org/ SciPy http://wiki.scipy.org/SciPy GUN Octave https://www.gnu.org/software/octave/

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB

Outline Get started Variable Operation Programming I/O Graphics Toolbox Before closing

Thank you for your attention and have fun R ! with MATLAB

Max-Planck-Institut f¨ ur Eisenforschung, D¨ usseldorf, Germany

Duancheng Ma,

R Introduction to MATLAB