Top Banner
by Jo Bergs An Introduction to Matlab
26

An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

May 05, 2018

Download

Documents

duongdang
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: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

by Jo Bergs

An Introduction to Matlab

Page 2: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Why Matlab?high-level scripting language => rapid prototypingcompatibility with established languages (java, C++, …) allows recoding of speed-limiting modulesexcellent interface and documentationlarge userbase with well-documented, ready-to-use applicationswell-suited for analysis of complex data

Page 3: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Interface – Main Menu

Variable Overview

Command History

Access to Toolbars

Console

Generated Plot

Working Directory!

Page 4: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Interface - Help

• Access via ordered list of content, indexed list or search• Search supports boolean operators• Demos including code• try „Getting Started“ and „Programming Fundamentals“• Inline help: in console, type <help command> (self-completing)• visit www.mathworks.com: user-made scripts and further help• code of built-in commands: <edit command>

Page 5: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Interface - Variable Editor• in variable overview: new variable -> doubleclick -> rightclick -> paste tabular data

OOF tables are imported

Page 6: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Interface - Designing GUIs

Property Inspector: by doubleclick on Object

Running Instance

GUIDE: GUI Designer

• WYSWG GUI Designer• Property Inspector defines Function „Connectivity“• Allows Design of custom-tailored data analysis tools

Page 7: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Compatibility• interoperable for windows and linux• callable from Fortran, C, Java and Python• Interface to Fortran, C and Java• allows prototyping in Matlab and subsequent replacement with faster languages• Full access to specialized libraries

Emulate a Click with Java:

(Mouse location set by Matlab, Input is a Java Robot Object)

Page 8: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Data Structures - Matrices• Matrix creation: embrace in < [ ] >, seperate values with < > or < , > and rows with < ; >

• invert Matrices with < ‘ >; concatenate with < [A; B ] > (size!)

• creating ranges: < Start:Stepsize(default=1):End >

Page 9: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Data Structures - Matrices

• creating random values: < rand(rows, cols) > (uniform) < randn(rows, cols) > (normal)

• creating multidimensional matrices by appending dimensions( < : > sets Start = 1 and End = row/column length)

• accessing values: < (row, column) >; ranges may be used

Page 10: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Data Structures - Matrices

• < sum(matrix) > sums column-wise; < mean(vector) > and std(vector, 1) forcalculatin the mean resp. Standard deviation

• putting it all together: evaluating docking results

• < sort(vector) > returns sorted vector and permutation index, which can beapplied to another vector via < vector(IDX) >

Page 11: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Data Structures – Cell Arrays• matrices can store boolean, integer, float and alphanumeric

• asymmetric data should to be stored in cell arrays with < {data1, data2; data3} >

• < cellplot(cellarray) > displays current structure of a cell array

Page 12: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Data Structures – Structs• container for cell arrays, matrices and single values

• allows named subvariables -> dictionary

• creation: < s = struct(‘name1‘, ‘content1‘, …) >

• access: column-wise with parenthesis or row-wise via name space

Page 13: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Programming - Basics• if and switch statements:

• for and while loops:

• error handling: (explicit error classes implemented)

• function definition (no indent needed):

Page 14: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Advanced Programming - GA• plot a function:

• define a fitness function and execute the GA:

Page 15: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Advanced Programming – Speed it Up!• vectorization allows usage of fast C libraries:

Faster!

• Runtime Profiler: < profile viewer > allows identification of expensive functions

Select Script

Time consumed by single function(dark blue: excluding subfunctions)

Page 16: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Advanced Programming – Debugging• editor with built-in debugger: on-line error warnings;

set break points; hover over vars to see value

Page 17: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Miscellaneous• use < … > as linebreak in code

• < display(variable) > prints variable value

• < whos variable > displays variable properties (no parentheses!)

• < save(‘path.mat‘) > stores all workspace variables as matlab .mat file

• < load(‘path.mat‘) > retrieves them

• < save(‘path.mat‘, ‘varname1‘,…) > stores/loads only specified vars

• functions for handling pdb files at MatlabCentral

• In Editor: File -> Publish allows publication of code with output or errors

Page 18: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Example – Score/RMSD• import docking results from .xls (!compatibility!):

• extract rmsd and score: cast to char, convert to floats

• sort both by rmsd:

Page 19: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Example – Scatter Plot• finally, plot it!

• no funnel-shapedness : (

Tune the Plot

Page 20: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Example – Plot Modifikation• label axis, set ticks, change markers, draw lines,…

Store the Plot

Page 21: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Example – Store your Work• File -> Save: stores the plot as .fig• File -> Generate M-File: stores code and allows to plug in new Data easily

Page 22: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Toolboxes - GA• toolboxes consists of functions and easy-to-use GUIs• GA and Direct Search toolbox: contains GA, SA and PSO

• parameter tuning • evaluation of convergence• comparison of search algorithm performance on a specific task

Fitness Functionand # Parameters

GoGoGo!

Algorithm

Page 23: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Other Toolboxes• stochastics toolbox: Cluster Analysis, Classifiers, Markov Models, …

• optimization toolbox: linear programming, model-fitting (least square)

• symbolic math toolbox: linear algebra, equation solver, calculus

• bioinformatics: sadly, no structural bioinformatics, but sequence analysis etc.

Page 24: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Our Book• Content:

− Solving linear Equations

− Interpolation

− Least Square Fitting

− Differential Equations

− Fourier Transformation

− Eigenvalues and PCA

Page 25: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Eyes Still Open?

Page 26: An Introduction to Matlab - uni-duesseldorf.decpclab.uni-duesseldorf.de/.../presentation_matlab.pdfAn Introduction to Matlab Why Matlab? zhigh-level scripting language => rapid prototyping

Thank you for your attention!