You are on page 1of 17

Introduction to MATLAB

TCIN Seminar

Lecture 1: Introduction
30 Jan 2009
What is Matlab?
• Matrix laboratory
• Programming environment
– Not “programs” per se
– Scripts
– Functions
Why Matlab?
• High-level syntax
• Consistent language
• Wide range of features
• Expandable (.m files)
• Ergonomic (help, autocompletion, historic,
etc...)
How to get Matlab?
• Several options:
– On campus:
• TCD computer labs
• Personal machines (ask me for CD)
– At home:
• Student edition (about 100 Euros)
• Academic edition (about 500 Euros)
• Octave (http://www.gnu.org/software/octave/)
• Scilab (http://www.scilab.org/)
This class:
• Objective for this class:
– Learning Matlab's basics
– Syllabus: TBD with you
– Use Matlab for your research
• Analysis
• Building stimuli
• Figures
Class web site
• Simplest way:
– www.utd.edu/~npenard
– Click on link in teaching section.
• Create account
• Forum
• homework
The

Matlab GUI: directory/workspace


window

The command
window

The history
window
Basics:
• Matrix based:

 
– Everything is matrix or array 1 5
• This is a 3 by 2 matrix 9 45
• In MATLAB: row 1st, column 2nd
8 2
• A scalar is a 1 by 1 “matrix”
– Matrix algebra built in.
– Case sensitive
Basics:
• Input a variable:
– Variable “stuff” is 8: stuff=8
• Important instructions:
– who, whos, why
– help, lookfor
– clear stuff, clear all
– Bonus: bench, auto-completion (not a
command, TAB key), history (arrows)
Basics:
• Binary coding:
– Over 8 bits (one byte)
• For instance:
128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 1 = 1
0 0 0 0 0 1 1 0 = 6
1 1 1 1 1 1 1 1 = 255

• Int8, uint8, int16, uint16 etc...


Basics:
• Operations:
– +, -, /, * and ^
• Reading directories:
– dir, ls, ls -l, mkdir and interface
• Save and load matrices:
– save name.mat name
– load name
• Useful:
– diary on, diary off
Basic mathematical function:
• Square root:
– sqrt(X)
• Trigonometric functions:
– cos(X), sin(X), tan(X) etc
• Logarithms:
– log(X), log10(X)
• Help elfun (elementary functions)
Basics:
• Input a matrix:
• A=[1 2 3; 4 5 6] This is
matrix A

– Or

• A=[1 2 3 (enter)
 1 2 3
4 5 6 
4 5 6] (enter)
Homework for next week:
• Create the following (2 by 3) matrix :

• Yourfirstname=
4

5 6
 cos91 A 
• With A=  2 / sin5
• Save it as yourfirstname.mat
Homework for next week:
• Create a second matrix named
“yourlastname” such as:
• yourlastname is the matrix yourfirstname
rounded to the next smallest integer.
– Hint: check the bottom of the output when
typing “help elfun”
• Save it as yourlastname.mat
• Send these 2 matrices to me.
Homework for next week:
• Another exercise:
• Create X:
X = 1 2 3 4 5 6 7 8 9 10 

• Compute Y and Z
2 2
Y=X Z =3× X −2×X 2
• Try this: W=[1:1000]
The End
• Next week:
– How to code simple scripts

You might also like