INTRODUCTION TO MATLABTM
http://www.matlab.com
General instructions
Open the Matlab program and input commands into the text-based window.
Type help <function name> to obtain information on Matlab functions.
Example help sin will provide information on the sin function.
lookfor <keyword> to do a key word search.
Ctrl + C to abort command.
pwd shows the current working director.
dir shows a file listing.
cd changes directory to the one specified e.g. cd a: will change to the a drive.
who displays the variables in the workspace.
clear clears the working directory.
Calculations using Matlab
Calculations may be done in the Matlab Environment using the following operators
+, -, *, / which represent addition, subtraction, multiplication and division.
Other useful mathematical functions are sqrt, ^, sin, asin, cos, acos, tan,
atan, log(base e) log10(base 10), abs, angle.
Programming environment
Variable names may be used for example if we let a=1, b=3, c=4, we can then set d=a+b+c.
d will equal 8. Variable names are case sensitive, can have up to 31 characters, they must start
with a letter and cannot contain punctuation.
Plotting functions
Results may be plotted using the plot, subplot, axis and hold functions. Plot
details can be included using the title, xlabel and ylabel functions
Two vectors (list of numbers) e.g. V for voltage and I for current with 20 elements each can
be plotted using the following syntax.
plot(I,V), title('Ohms Law'), xlabel('Current / Amps'),
ylabel('Voltage / Volts’).
A vector (list of numbers) with a variable name V is written into Matlab as
V = [ 1 2 3 4 5 6 7 8 9 10 ] note space between numbers.
Script m-files
A sequence of Matlab commands can be put together and run in sequence by saving a text file
with the commands as an m-file. There is a convenient text editor in Matlab. Go to file - new
m-file to start text editor or file - open m-file. A very useful command that can be used with
m-files is the input function. Example of how to request information for variable x
x = input(‘Enter value for x (state units) ’)
Comments can be added to the m-file if a % sign is placed before the comment.
INTRODUCTION TO MATLABTM
http://www.matlab.com
Vectors and Matrices
Vectors (list of numbers) and matrices are conveniently formed in rows. Square brackets
enclose the vector or matrix, commas separate elements of a row and semicolons separate
rows ( the commas can be excluded if a space is left between row elements).
Vector A=[ 2, 3, 4 ] or A=[ 2 3 4 ]
Matrix B=[ 3, 5, 6 ; 2, 6, 3 ] or B=[ 3 5 6 ; 2 6 3 ]
To transpose a vector or matrix use the ' operator.
Functions for producing vectors and matrices are:
rand, round, max, min, colon, linespace, logspace, zeros and
ones.
Matrix operations Operaion Matlab Element by Element
Addition A + B A + B A + B
Subtraction A - B A - B A - B
Multiplication A x B A * B A .* B
Division A / B A / B A ./ B
Indexing elements of vectors and matrices:
The first element of a vector is indexed by, 1 and the top left corner of a matrix is indexed by
(1,1)
Indexing examples a=A(2) will make variable a =3, b = B(2,2) will make variable b = 6.
Flow Control
Matlab has a number of flow control functions similar to standard programming languages
such as C programming e.g. for, while, and if else.
Function files
Function files are similar, to m-files except they have a formal set of input and output
variables. They are similar to sub routines in other programming languages.
The first line of the script must have the following format:
function [outputVariableList] = functionName(inputVariableList)
the m file name must be the same as the functionName
INTRODUCTION TO MATLABTM
http://www.matlab.com
Short list of Matlab Functions
function example comment
- x = (6-3) subtraction
% % code comments used to enter comments in m-file or
function
* x = (2*3) multiplication, use brackets for clarity
.* z = x.*y element by element vector or matrix
multiplication, note dot before *
./ z = x./y element by element division
/ x = (4/2) division
^ x = 2^3 2 to the power of 3
+ x = (2+4) addition
abs x = abs(3+4j) magnitude of a complex number
acos x = acos(0.5) inverse cos, note answer is in radians
angle x = angle(3+4j) angle of a complex number
asin x = asin(0.5) inverse sin, note answer is in radians
cd cd a: change directory or drive
clear clear empty workspace
conj x = conj(3+4j) conjugate of 3+4j
conv y = conv([1 2],[ 1 2 1]) convolution or polynomial multiplication
cos x = cos(1.5) cos of an angle, note angle should be in
radians
deconv x = deconv( [1 2 1],[1 2]) polynomial division
dir dir list files
exp x = exp(-0.5) e to the power of -0.5, note e
= 2.7183
freqs [h,w] = freqs(b,a) frequency resposne of Transfer Function
b = laplace numerator coefficients and a
= denominator coefficients use with
semilogx
function function c = myadd(a,b)
%help comments here
c=a+b
fprintf('answer = %g',c)
funtion to add two numbers, fprintf
provides formatted output, file name
should be same as fucntion name
myadd.m
ginput ginput(n) extract n x-y points from graphs
help help rand help will provide help on function
specified
INTRODUCTION TO MATLABTM
http://www.matlab.com
hold on hold on allows multiple plots on the one graph
imag b = imag(z) imaginary part of z
input x = input('request data from user') used to request data from user, data given
to variable x
length lx = length(x) determine the length of vector x, number
of values
log x = log(20) log to the base e
log10 x = log10(20) log to the base10
lookfor lookfor rand lookfor will find information on the text
string specified
max [m,i] = max([ 1 2 4 2]) maximium value and position
plot plot(x,y) plots vectors y against x
pwd pwd shows current directory
rand x = rand(1,20) 20 random numbers between 0-1
real a = real(z) real part of complex number z
residue [R P K]=residue(1, [1 2 1]) determine partial fraction expansion of
transfer fucntion
roots x=roots( [1 2 1]) roots of polynomial with coefficients [1 2
1]
semilogx semilogx(w,h) plots linear y axis against log x axis
sin x = sin(1.5) sin of an angle, note angle should be in
radians
sqrt x = sqrt(9) square root of a number
stem stem(n,v) Discrete signal plot
subplot subplot(2,2,1), plot(x,y),
title('info'),xlabel('info'),ylabel('info')
2 x 2 set of plots
sum x = sum(x) Add values of vector x
title title('plot title') title for plot
who who shows variables in workspace
x' x' transpose vector or matrix x
xlable xlabel('x label information') x lable quantity / units
ylabel ylabel('y label information') y label quantity / units

More Related Content

PPTX
C,C++ In Matlab
PPTX
Procedures And Functions in Matlab
PPT
Matlab1
PPTX
Matlab 1(operations on_matrix)
PPT
Matlab anilkumar
PPT
Matlab intro
DOCX
MATLAB BASICS
PPTX
Matlab Functions
C,C++ In Matlab
Procedures And Functions in Matlab
Matlab1
Matlab 1(operations on_matrix)
Matlab anilkumar
Matlab intro
MATLAB BASICS
Matlab Functions

What's hot (20)

PPT
Introduction to MatLab programming
PPTX
Introduction to matlab
PDF
Matlab commands
PPT
Introduction to MATLAB
PDF
Introduction to MATLAB
PPT
Csc1100 lecture14 ch16_pt2
PDF
MATLAB Programming
PPTX
Importance of matlab
DOCX
B61301007 matlab documentation
PDF
4 R Tutorial DPLYR Apply Function
PPT
Matlab introduction
PDF
Introduction to MATLAB
PPTX
MATLAB - The Need to Know Basics
PDF
Matlab functions
PPTX
Intro to Matlab programming
PPTX
PDF
R basics
 
PDF
Matlab solved problems
PDF
3 R Tutorial Data Structure
PDF
Matlab commands
Introduction to MatLab programming
Introduction to matlab
Matlab commands
Introduction to MATLAB
Introduction to MATLAB
Csc1100 lecture14 ch16_pt2
MATLAB Programming
Importance of matlab
B61301007 matlab documentation
4 R Tutorial DPLYR Apply Function
Matlab introduction
Introduction to MATLAB
MATLAB - The Need to Know Basics
Matlab functions
Intro to Matlab programming
R basics
 
Matlab solved problems
3 R Tutorial Data Structure
Matlab commands

Viewers also liked (8)

PDF
Program for narrow beam program matlab
PDF
Matlab plotting
PDF
Signal Prosessing Lab Mannual
PDF
Manual for the MATLAB program to solve the 2D truss
PDF
solution for 2D truss1
PDF
Dsp lab manual
DOC
Digital Signal Processing Lab Manual ECE students
PDF
Introduction to Digital Image Processing Using MATLAB
Program for narrow beam program matlab
Matlab plotting
Signal Prosessing Lab Mannual
Manual for the MATLAB program to solve the 2D truss
solution for 2D truss1
Dsp lab manual
Digital Signal Processing Lab Manual ECE students
Introduction to Digital Image Processing Using MATLAB

Similar to Introduction to matlab (20)

DOCX
Introduction to matlab
PPTX
Raushan's MATLB PPT..pptx
PPT
Introduction to Matlab - Basic Functions
PPT
MatlabIntro (1).ppt
PPT
MatlabIntro1234.ppt.....................
PPT
Matlab Basic Tutorial
PPT
MatlabIntro.ppt
PPT
MatlabIntro.ppt
PPT
MatlabIntro.ppt
PPT
MatlabIntro.ppt
PPT
WIDI FREAK MANUSIA SETENGAH EDIOTDAN LEMBOT
PPT
matlab_tutorial.ppt
PPT
matlab_tutorial.ppt
PPT
matlab_tutorial.ppt
PDF
Lecture 01 variables scripts and operations
PPTX
3_MATLAB Basics Introduction for Engineers .pptx
PPT
WIDI ediot autis dongok part 2.ediot lu lembot lu
PPT
WIDI ediot autis dongok part 3.EDIOT LU LEMBOT LY
PPTX
Mat lab workshop
PPT
Matlab Tutorial.ppt
Introduction to matlab
Raushan's MATLB PPT..pptx
Introduction to Matlab - Basic Functions
MatlabIntro (1).ppt
MatlabIntro1234.ppt.....................
Matlab Basic Tutorial
MatlabIntro.ppt
MatlabIntro.ppt
MatlabIntro.ppt
MatlabIntro.ppt
WIDI FREAK MANUSIA SETENGAH EDIOTDAN LEMBOT
matlab_tutorial.ppt
matlab_tutorial.ppt
matlab_tutorial.ppt
Lecture 01 variables scripts and operations
3_MATLAB Basics Introduction for Engineers .pptx
WIDI ediot autis dongok part 2.ediot lu lembot lu
WIDI ediot autis dongok part 3.EDIOT LU LEMBOT LY
Mat lab workshop
Matlab Tutorial.ppt

More from Sourabh Bhattacharya (20)

PDF
Operational%20 amplifier
PDF
Sms based wireless appliances control
DOCX
Energy merter
PDF
Comm network
PPT
132 kv seminar ppt
PDF
Introduction to matlab
PDF
Matlab files
PDF
Matlab booklet

Recently uploaded (20)

PDF
Launch a Bumble-Style App with AI Features in 2025.pdf
PDF
Introduction to MCP and A2A Protocols: Enabling Agent Communication
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
A symptom-driven medical diagnosis support model based on machine learning te...
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PPTX
How to use fields_get method in Odoo 18
PPTX
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
PDF
Human Computer Interaction Miterm Lesson
PPTX
Presentation - Principles of Instructional Design.pptx
PDF
SaaS reusability assessment using machine learning techniques
PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PPTX
Information-Technology-in-Human-Society.pptx
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
Co-training pseudo-labeling for text classification with support vector machi...
Launch a Bumble-Style App with AI Features in 2025.pdf
Introduction to MCP and A2A Protocols: Enabling Agent Communication
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
A symptom-driven medical diagnosis support model based on machine learning te...
Rapid Prototyping: A lecture on prototyping techniques for interface design
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
giants, standing on the shoulders of - by Daniel Stenberg
How to use fields_get method in Odoo 18
Rise of the Digital Control Grid Zeee Media and Hope and Tivon FTWProject.com
Human Computer Interaction Miterm Lesson
Presentation - Principles of Instructional Design.pptx
SaaS reusability assessment using machine learning techniques
Build automations faster and more reliably with UiPath ScreenPlay
Information-Technology-in-Human-Society.pptx
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
Co-training pseudo-labeling for text classification with support vector machi...

Introduction to matlab

  • 1. INTRODUCTION TO MATLABTM http://www.matlab.com General instructions Open the Matlab program and input commands into the text-based window. Type help <function name> to obtain information on Matlab functions. Example help sin will provide information on the sin function. lookfor <keyword> to do a key word search. Ctrl + C to abort command. pwd shows the current working director. dir shows a file listing. cd changes directory to the one specified e.g. cd a: will change to the a drive. who displays the variables in the workspace. clear clears the working directory. Calculations using Matlab Calculations may be done in the Matlab Environment using the following operators +, -, *, / which represent addition, subtraction, multiplication and division. Other useful mathematical functions are sqrt, ^, sin, asin, cos, acos, tan, atan, log(base e) log10(base 10), abs, angle. Programming environment Variable names may be used for example if we let a=1, b=3, c=4, we can then set d=a+b+c. d will equal 8. Variable names are case sensitive, can have up to 31 characters, they must start with a letter and cannot contain punctuation. Plotting functions Results may be plotted using the plot, subplot, axis and hold functions. Plot details can be included using the title, xlabel and ylabel functions Two vectors (list of numbers) e.g. V for voltage and I for current with 20 elements each can be plotted using the following syntax. plot(I,V), title('Ohms Law'), xlabel('Current / Amps'), ylabel('Voltage / Volts’). A vector (list of numbers) with a variable name V is written into Matlab as V = [ 1 2 3 4 5 6 7 8 9 10 ] note space between numbers. Script m-files A sequence of Matlab commands can be put together and run in sequence by saving a text file with the commands as an m-file. There is a convenient text editor in Matlab. Go to file - new m-file to start text editor or file - open m-file. A very useful command that can be used with m-files is the input function. Example of how to request information for variable x x = input(‘Enter value for x (state units) ’) Comments can be added to the m-file if a % sign is placed before the comment.
  • 2. INTRODUCTION TO MATLABTM http://www.matlab.com Vectors and Matrices Vectors (list of numbers) and matrices are conveniently formed in rows. Square brackets enclose the vector or matrix, commas separate elements of a row and semicolons separate rows ( the commas can be excluded if a space is left between row elements). Vector A=[ 2, 3, 4 ] or A=[ 2 3 4 ] Matrix B=[ 3, 5, 6 ; 2, 6, 3 ] or B=[ 3 5 6 ; 2 6 3 ] To transpose a vector or matrix use the ' operator. Functions for producing vectors and matrices are: rand, round, max, min, colon, linespace, logspace, zeros and ones. Matrix operations Operaion Matlab Element by Element Addition A + B A + B A + B Subtraction A - B A - B A - B Multiplication A x B A * B A .* B Division A / B A / B A ./ B Indexing elements of vectors and matrices: The first element of a vector is indexed by, 1 and the top left corner of a matrix is indexed by (1,1) Indexing examples a=A(2) will make variable a =3, b = B(2,2) will make variable b = 6. Flow Control Matlab has a number of flow control functions similar to standard programming languages such as C programming e.g. for, while, and if else. Function files Function files are similar, to m-files except they have a formal set of input and output variables. They are similar to sub routines in other programming languages. The first line of the script must have the following format: function [outputVariableList] = functionName(inputVariableList) the m file name must be the same as the functionName
  • 3. INTRODUCTION TO MATLABTM http://www.matlab.com Short list of Matlab Functions function example comment - x = (6-3) subtraction % % code comments used to enter comments in m-file or function * x = (2*3) multiplication, use brackets for clarity .* z = x.*y element by element vector or matrix multiplication, note dot before * ./ z = x./y element by element division / x = (4/2) division ^ x = 2^3 2 to the power of 3 + x = (2+4) addition abs x = abs(3+4j) magnitude of a complex number acos x = acos(0.5) inverse cos, note answer is in radians angle x = angle(3+4j) angle of a complex number asin x = asin(0.5) inverse sin, note answer is in radians cd cd a: change directory or drive clear clear empty workspace conj x = conj(3+4j) conjugate of 3+4j conv y = conv([1 2],[ 1 2 1]) convolution or polynomial multiplication cos x = cos(1.5) cos of an angle, note angle should be in radians deconv x = deconv( [1 2 1],[1 2]) polynomial division dir dir list files exp x = exp(-0.5) e to the power of -0.5, note e = 2.7183 freqs [h,w] = freqs(b,a) frequency resposne of Transfer Function b = laplace numerator coefficients and a = denominator coefficients use with semilogx function function c = myadd(a,b) %help comments here c=a+b fprintf('answer = %g',c) funtion to add two numbers, fprintf provides formatted output, file name should be same as fucntion name myadd.m ginput ginput(n) extract n x-y points from graphs help help rand help will provide help on function specified
  • 4. INTRODUCTION TO MATLABTM http://www.matlab.com hold on hold on allows multiple plots on the one graph imag b = imag(z) imaginary part of z input x = input('request data from user') used to request data from user, data given to variable x length lx = length(x) determine the length of vector x, number of values log x = log(20) log to the base e log10 x = log10(20) log to the base10 lookfor lookfor rand lookfor will find information on the text string specified max [m,i] = max([ 1 2 4 2]) maximium value and position plot plot(x,y) plots vectors y against x pwd pwd shows current directory rand x = rand(1,20) 20 random numbers between 0-1 real a = real(z) real part of complex number z residue [R P K]=residue(1, [1 2 1]) determine partial fraction expansion of transfer fucntion roots x=roots( [1 2 1]) roots of polynomial with coefficients [1 2 1] semilogx semilogx(w,h) plots linear y axis against log x axis sin x = sin(1.5) sin of an angle, note angle should be in radians sqrt x = sqrt(9) square root of a number stem stem(n,v) Discrete signal plot subplot subplot(2,2,1), plot(x,y), title('info'),xlabel('info'),ylabel('info') 2 x 2 set of plots sum x = sum(x) Add values of vector x title title('plot title') title for plot who who shows variables in workspace x' x' transpose vector or matrix x xlable xlabel('x label information') x lable quantity / units ylabel ylabel('y label information') y label quantity / units