Scholarly network analysis

advertisement
Informetric methods seminar
Tutorial 1: Matlab basics
Erjia Yan
Contents
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
Getting started
 Install and use Matlab
 Data format in Matlab
 Export and import data in Matlab
 Useful functions and commands
 Programming in Matlab
 Resources

Some screenshots are taken from www.mathworks.com
Matlab key features





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®
http://www.mathworks.com/products/matlab/description1.html
Contents
Getting started
 Install and use Matlab
 Data format in Matlab
 Export and import data in Matlab
 Useful functions and commands
 Programming in Matlab
 Resources

Access Matlab in IU

Desktop installation
Per year
Only available on university-owned computers
Students can purchase directly from Mathworks.com
For students
Free IU Anyware access

https://iuanyware.iu.edu/vpn/index.html
Free UITS desktop access
East and west tower desktops
 And most UITS desktops on campus, except
for stand-alone informstations

Quarry…
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

Interface
http://www.tufts.edu/~rwhite07/Matlab_files/image017.jpg
Image interface
http://www.aquaphoenix.com/lecture/matlab10/imageslarge/matlab_audio_funky_plot_spectrogram_detail.jpg
Contents
Getting started
 Install and use Matlab
 Data format in Matlab
 Export and import data in Matlab
 Useful functions and commands
 Programming in Matlab
 Resources

Variables
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
Arrays and matrix

row=[1,2,3,4,5]


a 1*5 matrix
column=[1;2;3;4;5]


You can give any
variable names to
row and column.
a 5*1 matrix
a=[1,2;3,4]

a 2*2 matrix
a=
1 2
3 4
Contents
Getting started
 Install and use Matlab
 Data format in Matlab
 Export and import data in Matlab
 Useful functions and commands
 Programming in Matlab
 Resources

Full matrix read
a=xlsread(filename)
 a=xlsread(filename,sheet)
 a=xlsread(filename,xlRange)
 a=xlsread(filename,sheet,xlRange)

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/dataimport-and-export.html
Full matrix write
xlswrite(filename,A)
 xlswrite(filename,A,sheet)
 xlswrite(filename,A,xlRange)
 xlswrite(filename,A,sheet,xlRange)

CSV files
a = csvread(filename,row,col)
 csvwrite(filename,a,row,col)

row and col are zero based,
meaning that they start
from 0 but not 1
Sparse matrix import
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 export
You can use mmwrite(filename,M)
 http://math.nist.gov/MatrixMarket/mmio/matla
b/mmiomatlab.html

Contents
Getting started
 Install and use Matlab
 Data format in Matlab
 Export and import data in Matlab
 Useful functions and commands
 Programming in Matlab
 Resources

Operators

Arithmetic operations (+,-,*,/)


4+5*7-2
Exponentiation (^)

2^3=8
Built-in 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…
For matrices

Transpose
transpose(M)
 M’


1
M=
3
2
4
Addition and subtraction
1
M’=
2
1
 M-M’=
3
2
1 3 0
−
=
4
2 4 1
−1
0
1
 M+M’=
3
2
1 3 2
+
=
4
2 4 5
5
8
3
4
Multiplication and division


For element-wise operations, use the dot: .(.*,
./, .^)
1
 M.*M’=
3
2
1
.∗
4
2
3 1 6
=
4 6 16
1
 M./M’=
3
2
1
./
4
2
1
3
=
4 3/2
Matrix operations
1
 M*M’=
3
2
1
∗
4
2
3
5
=
4 11
2/3
1
11
25
Indexing
1 2
M=
3 4
M(1,1)=1; M(1,2)=2
 M(1,:)=[1 2]
2
 M(1:2,2)=

4
Contents
Getting started
 Install and use Matlab
 Data format in Matlab
 Export and import data in Matlab
 Useful functions and commands
 Programming in Matlab
 Resources

Command line
M file
Advanced programming

Compiler


http://www.mathworks.com/products/compiler/
Object-Oriented Programming

http://www.mathworks.com/discovery/objectoriented-programming.html
Contents
Getting started
 Install and use Matlab
 Data format in Matlab
 Export and import data in Matlab
 Useful functions and commands
 Programming in Matlab
 Resources

Free resources
help command in Matlab…the most useful
 Matlab Central



MIT Open Course


http://www.mathworks.com/matlabcentral/
http://ocw.mit.edu/courses/electrical-engineeringand-computer-science/6-094-introduction-tomatlab-january-iap-2010/lecture-notes/
Google “matlab + keywords”
Download