SlideShare a Scribd company logo
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

What's hot

Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
Damian T. Gordon
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Khulna University
 
Matlab commands
Matlab commandsMatlab commands
Matlab commands
avinashkumer
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Damian T. Gordon
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Sarah Hussein
 
Csc1100 lecture14 ch16_pt2
Csc1100 lecture14 ch16_pt2Csc1100 lecture14 ch16_pt2
Csc1100 lecture14 ch16_pt2
IIUM
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
محمدعبد الحى
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
krajeshk1980
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
Manchireddy Reddy
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function
Sakthi Dasans
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Satish Gummadi
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Dun Automation Academy
 
MATLAB - The Need to Know Basics
MATLAB - The Need to Know BasicsMATLAB - The Need to Know Basics
MATLAB - The Need to Know Basics
STEM Course Prep
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
pramodkumar1804
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
Ahmed Moawad
 
Mbd2
Mbd2Mbd2
R basics
R basicsR basics
R basics
FAO
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
Make Mannan
 
3 R Tutorial Data Structure
3 R Tutorial Data Structure3 R Tutorial Data Structure
3 R Tutorial Data Structure
Sakthi Dasans
 
Matlab commands
Matlab commandsMatlab commands
Matlab commands
Tarun Gehlot
 

What's hot (20)

Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab commands
Matlab commandsMatlab commands
Matlab commands
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Csc1100 lecture14 ch16_pt2
Csc1100 lecture14 ch16_pt2Csc1100 lecture14 ch16_pt2
Csc1100 lecture14 ch16_pt2
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
MATLAB - The Need to Know Basics
MATLAB - The Need to Know BasicsMATLAB - The Need to Know Basics
MATLAB - The Need to Know Basics
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
 
Mbd2
Mbd2Mbd2
Mbd2
 
R basics
R basicsR basics
R basics
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
 
3 R Tutorial Data Structure
3 R Tutorial Data Structure3 R Tutorial Data Structure
3 R Tutorial Data Structure
 
Matlab commands
Matlab commandsMatlab commands
Matlab commands
 

Viewers also liked

Program for narrow beam program matlab
Program for narrow beam program matlabProgram for narrow beam program matlab
Program for narrow beam program matlab
Indian Institute of Technology, Bombay
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
Amr Rashed
 
Signal Prosessing Lab Mannual
Signal Prosessing Lab Mannual Signal Prosessing Lab Mannual
Signal Prosessing Lab Mannual
Jitendra Jangid
 
Manual for the MATLAB program to solve the 2D truss
Manual for the MATLAB program to solve the 2D trussManual for the MATLAB program to solve the 2D truss
Manual for the MATLAB program to solve the 2D truss
Mohammaderfan Zandieh
 
solution for 2D truss1
solution for 2D truss1solution for 2D truss1
solution for 2D truss1
Mohammaderfan Zandieh
 
Dsp lab manual
Dsp lab manualDsp lab manual
Dsp lab manual
Mukul Mohal
 
Digital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE studentsDigital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE students
UR11EC098
 
Introduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLABIntroduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLAB
Ray Phan
 

Viewers also liked (8)

Program for narrow beam program matlab
Program for narrow beam program matlabProgram for narrow beam program matlab
Program for narrow beam program matlab
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Signal Prosessing Lab Mannual
Signal Prosessing Lab Mannual Signal Prosessing Lab Mannual
Signal Prosessing Lab Mannual
 
Manual for the MATLAB program to solve the 2D truss
Manual for the MATLAB program to solve the 2D trussManual for the MATLAB program to solve the 2D truss
Manual for the MATLAB program to solve the 2D truss
 
solution for 2D truss1
solution for 2D truss1solution for 2D truss1
solution for 2D truss1
 
Dsp lab manual
Dsp lab manualDsp lab manual
Dsp lab manual
 
Digital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE studentsDigital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE students
 
Introduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLABIntroduction to Digital Image Processing Using MATLAB
Introduction to Digital Image Processing Using MATLAB
 

Similar to Introduction to matlab

Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
Muhammad Rizwan
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Tarun Gehlot
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
AkashSingh728626
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
MahuaPal6
 
Matlab Manual
Matlab ManualMatlab Manual
Tutorial2
Tutorial2Tutorial2
Tutorial2
ashumairitar
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
Dr. Krishna Mohbey
 
Brief Introduction to Matlab
Brief  Introduction to MatlabBrief  Introduction to Matlab
Brief Introduction to Matlab
Tariq kanher
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
vikrammutneja1
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
SungaleliYuen
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
ssuser43b38e
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
ShwetaPandey248972
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
konkatisandeepkumar
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
ssuser772830
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
Rajmohan Madasamy
 
Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06
Aman kazmi
 
Kevin merchantss
Kevin merchantssKevin merchantss
Kevin merchantss
dharmesh69
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTKEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENT
tejas1235
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
prashantkumarchinama
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Ameen San
 

Similar to Introduction to matlab (20)

Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
 
Matlab Manual
Matlab ManualMatlab Manual
Matlab Manual
 
Tutorial2
Tutorial2Tutorial2
Tutorial2
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
Brief Introduction to Matlab
Brief  Introduction to MatlabBrief  Introduction to Matlab
Brief Introduction to Matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06
 
Kevin merchantss
Kevin merchantssKevin merchantss
Kevin merchantss
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTKEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENT
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 

More from Sourabh Bhattacharya

Operational%20 amplifier
Operational%20 amplifierOperational%20 amplifier
Operational%20 amplifier
Sourabh Bhattacharya
 
Sms based wireless appliances control
Sms based wireless appliances controlSms based wireless appliances control
Sms based wireless appliances control
Sourabh Bhattacharya
 
Energy merter
Energy merterEnergy merter
Energy merter
Sourabh Bhattacharya
 
Comm network
Comm networkComm network
Comm network
Sourabh Bhattacharya
 
132 kv seminar ppt
132 kv seminar ppt132 kv seminar ppt
132 kv seminar ppt
Sourabh Bhattacharya
 
132 kv
132 kv132 kv
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Sourabh Bhattacharya
 
Matlab files
Matlab filesMatlab files
Matlab files
Sourabh Bhattacharya
 
Matlab booklet
Matlab bookletMatlab booklet
Matlab booklet
Sourabh Bhattacharya
 

More from Sourabh Bhattacharya (20)

Vhdl2
Vhdl2Vhdl2
Vhdl2
 
Vhdl
VhdlVhdl
Vhdl
 
Operational%20 amplifier
Operational%20 amplifierOperational%20 amplifier
Operational%20 amplifier
 
Mai506
Mai506Mai506
Mai506
 
M&i605
M&i605M&i605
M&i605
 
M&i
M&iM&i
M&i
 
Lica605
Lica605Lica605
Lica605
 
Lica506
Lica506Lica506
Lica506
 
Lica
LicaLica
Lica
 
Itc605
Itc605Itc605
Itc605
 
Itc
ItcItc
Itc
 
Vlsi707
Vlsi707Vlsi707
Vlsi707
 
Sms based wireless appliances control
Sms based wireless appliances controlSms based wireless appliances control
Sms based wireless appliances control
 
Energy merter
Energy merterEnergy merter
Energy merter
 
Comm network
Comm networkComm network
Comm network
 
132 kv seminar ppt
132 kv seminar ppt132 kv seminar ppt
132 kv seminar ppt
 
132 kv
132 kv132 kv
132 kv
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab files
Matlab filesMatlab files
Matlab files
 
Matlab booklet
Matlab bookletMatlab booklet
Matlab booklet
 

Recently uploaded

How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 

Recently uploaded (20)

How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 

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