Top Banner
Informetric methods seminar Tutorial 1: Matlab basics Erjia Yan
33

Tutorial 1: Matlab basics Erjia Yan. Getting started Install and use Matlab Data format in Matlab Export and import data in Matlab Useful functions.

Dec 25, 2015

Download

Documents

Solomon Carter
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Informetric methods seminar

Tutorial 1: Matlab basicsErjia Yan

Page 2: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Getting started Install and use Matlab Data format in Matlab Export and import data in Matlab Useful functions and commands Programming in Matlab Resources

Contents

Page 3: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Getting started Install and use Matlab Data format in Matlab Export and import data in Matlab Useful functions and commands Programming in Matlab Resources

Contents

Some screenshots are taken from www.mathworks.com

Page 4: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

High-level language for numerical computation, visualization, and application development

Built-in mathematical functions for linear algebra, statistics, matrix manipulation, etc.

Extensive tool-boxes (e.g., accounting, bioinformatics, etc.)

Built-in graphics for visualizing data and tools for creating custom plots

Functions for integrating MATLAB based algorithms with external applications and languages such as C, Java, .NET, and Microsoft® Excel®

Matlab key features

http://www.mathworks.com/products/matlab/description1.html

Page 5: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Getting started Install and use Matlab Data format in Matlab Export and import data in Matlab Useful functions and commands Programming in Matlab Resources

Contents

Page 6: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Desktop installation

Access Matlab in IU

Per yearOnly available on university-owned computersStudents can purchase directly from Mathworks.com

Page 7: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

For students

Page 8: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

https://iuanyware.iu.edu/vpn/index.html

Free IU Anyware access

Page 9: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

East and west tower desktops And most UITS desktops on campus,

except for stand-alone informstations

Free UITS desktop access

Page 10: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

http://racinfo.indiana.edu/hps/quarry For large data processing; batch file-

based Need to register an account before

using Windows users can use WinSCP and

Putty to upload/download files and send commands

Quarry…

Page 11: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Interface

http://www.tufts.edu/~rwhite07/Matlab_files/image017.jpg

Page 12: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Image interface

http://www.aquaphoenix.com/lecture/matlab10/images-large/matlab_audio_funky_plot_spectrogram_detail.jpg

Page 13: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Getting started Install and use Matlab Data format in Matlab Export and import data in Matlab Useful functions and commands Programming in Matlab Resources

Contents

Page 14: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Number: 4.34 Character: ‘variable_name’ Do not need to state variable types

a=4.34 cellname=‘networks’

Built-in variable (do not use them) pi, Inf, -Inf, ans, NaN

Variables

Page 15: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

row=[1,2,3,4,5] a 1*5 matrix

column=[1;2;3;4;5] a 5*1 matrix

a=[1,2;3,4] a 2*2 matrix

Arrays and matrix

You can give any variable names to row and column.

a=

Page 16: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Getting started Install and use Matlab Data format in Matlab Export and import data in Matlab Useful functions and commands Programming in Matlab Resources

Contents

Page 17: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

a=xlsread(filename) a=xlsread(filename,sheet) a=xlsread(filename,xlRange) a=xlsread(filename,sheet,xlRange)

Full matrix read

For other import and export functions in Matlab, such as textual data, XML, etc., you can find relevant information here: http://www.mathworks.com/help/matlab/data-import-and-export.html

Page 18: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

xlswrite(filename,A) xlswrite(filename,A,sheet) xlswrite(filename,A,xlRange) xlswrite(filename,A,sheet,xlRange)

Full matrix write

Page 19: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

a = csvread(filename,row,col) csvwrite(filename,a,row,col)

CSV files

row and col are zero based, meaning that they start from 0 but not 1

Page 20: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

S = spconvert(D) Sparse matrix format

row_id col_id value First use load to upload the data into

Matlab and then use spconvert to convert the data into a matrix load datasample.txt M = spconvert(datasample)

Sparse matrix import

Page 21: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

You can use mmwrite(filename,M) http://math.nist.gov/MatrixMarket/m

mio/matlab/mmiomatlab.html

Sparse matrix export

Page 22: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Getting started Install and use Matlab Data format in Matlab Export and import data in Matlab Useful functions and commands Programming in Matlab Resources

Contents

Page 23: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Arithmetic operations (+,-,*,/) 4+5*7-2

Exponentiation (^) 2^3=8

Operators

Page 24: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

sqrt(2) log(2), log10(0.23) cos(1.2), atan(-.8) exp(2+4*i) round(1.4)=1, floor(3.9)=3,

ceil(4.23)=5 plot(x,y)

And countless more…

Built-in functions

Page 25: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Transpose transpose(M) M’

Addition and subtraction M-M’=

M+M’=

For matrices

M= M’=

=

=

Page 26: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

For element-wise operations, use the dot: .(.*, ./, .^) M.*M’=

M./M’=

Matrix operations M*M’=

Multiplication and division

=

=

=

Page 27: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

M(1,1)=1; M(1,2)=2 M(1,:)=[1 2] M(1:2,2)=

Indexing

M=

[ 24 ]

Page 28: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Getting started Install and use Matlab Data format in Matlab Export and import data in Matlab Useful functions and commands Programming in Matlab Resources

Contents

Page 29: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Command line

Page 30: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

M file

Page 32: Tutorial 1: Matlab basics Erjia Yan.  Getting started  Install and use Matlab  Data format in Matlab  Export and import data in Matlab  Useful functions.

Getting started Install and use Matlab Data format in Matlab Export and import data in Matlab Useful functions and commands Programming in Matlab Resources

Contents