SlideShare a Scribd company logo
An Introduction to MatlabDr Andrew Wallace PhD BEng(hons) EurIngC-124a
OverviewThe command windowInputs and outputsM files
Current DirectoryCommand WindowCommand History
The Command WindowMatrix basedEntering a matrixa = [ 1 2 3; 4 5 6; 7 8 9]
The Command WindowBuilt in FunctionsSumTranspose (‘)Diag
The Command WindowLocating an element in a matrixa(i, j) (row i, column j):
The Command WindowEnd
The Command WindowBasic maths commands+  	addition- 	subtraction* 	multiplication/ 	division^	Power()	Precedence
The Command WindowAdding matricesa+ba(i,j) + b(i,j)MultiplicationA rows = b columns
The Command WindowElement by element operators.*./.^
The Command WindowCombining matricesConstruct a matrix with matrices inside it!b = [a, a; a, a]Deleting rows and columnsa(:, 2) = []a(1,:) = []
The Command WindowFormatControl the display formatshort or longrat or hexe or eng
The Command WindowEditing the command lineUse the Use command history
The Command Window:Creates arrays<start> : <end>Add spacing<start> : <spacing> : <end>
Inputs and Outputsfid = fopen(<file name>, ‘<read write access>')fprintf(fid, ‘<string>', <variables>)%s\t%d\n
The Command Window
Inputs and OutputsLoadLoads in data in either binary of ascii format
Inputs and OutputsLoading imagesimread(‘<filename’)
An introduction to matlab
Inputs and OutputsM filesCommandsAs you would type them into the command windowFile ends with “.m”Functions
Inputs and Outputsplot(x,y)Display graphsx=0:pi/100:2*pisin(x)
Inputs and OutputsAdding informationxlable and ylableBoth take a text argument ‘<text>’title(‘<name>’, [‘<property name>’], [value])PropertiesFontColour	legend(‘<text>’, ‘<text>’ …)Text for each data set
Inputs and OutputsLine stylesPlot(x, y, [‘<colour / style’])c, m, y, r, g, b, w, k‘-’,    	‘- -’, 	‘:’, 	‘- .’Marker types‘+’	‘o’	‘*’	‘x’	‘<‘	‘>’	‘^’ 	‘v’‘s’	‘d’ 	‘p’	‘h’plot(x,y,’k-s’)
Inputs and Outputs
Inputs and Outputsholdon or offAllows plotting to the current graph			[x,y,z]= peaks			contour(x,y,z,20,’k’)			hold onpcolour(x,y,z)			shading interp			hold off
Inputs and Outputs
Inputs and Outputs[x,y]=meshgrid(-8:.5:8);r=sqrt(x.^2+y.^2)+eps;z = sin(r)./r;mesh(x,y,z,'EdgeColor','black');
Inputs and Outputs
Inputs and Outputssurf(x,y,z)colormaphsvcolorbar
Inputs and Outputs
M FilesCommandsFunctionsLike a program fileFunction headersfunction [<outputs>] = FunctionName(<inputs>Function name = name of the fileFunctionName.m
M Filesfunction Wrist(VOnset, Dist)function [Max, Idx] = FindAllMax(Data, Offset)
M FilesBuilding blocksConditionalsIFSWITCHLoopsFORWHILECONTINUEBREAK
M FilesConditionalsIf <condition>	…else if <condition>	…else	…end
M Filesif NumOfMarkers < 10XYZData = PadOutData(XYZData, 						NumOfMarkers)Endif VelOnSet > YOnSetOnsetBk = VelOnSetelseOnsetBk = YOnSetend
M Filesswitch (<condition>)	case …		…	case …		…	otherwise		…end
M Filesswitch (rem(n,4)==0) + (rem(n,2)==0)	case 0 		M = odd_magic(n) 	case 1 		M = single_even_magic(n) 	case 2 		M = double_even_magic(n) 	otherwise 		error('This is impossible') end
M FilesLoopsForwhile
M Filesfor <index> = <start>:<end>	…endfor i = 1:length(XCoorHWL)	if XCoorHWLMax < XCoorHWL(i)XCoorHWLMax = XCoorHWL(i)        	XCoorHWLMaxIdx =  i	endend
M FilesWhile <condition>…endwhile (a < g_OnsetVel)VelOnSet = VelOnSet + 1    a = vel(VelOnSet)end
M FilesconditionFor loopNext iterationbreakExit earlytry	…catch exceptObj	…end
Questions?

More Related Content

PPTX
Graph Plots in Matlab
PPT
Lecture on graphics
PPTX
Matlab Visualizing Data
PDF
R-Excel Integration
PDF
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
DOCX
R scatter plots
PDF
Py lecture5 python plots
PDF
Scala collection methods flatMap and flatten are more powerful than monadic f...
Graph Plots in Matlab
Lecture on graphics
Matlab Visualizing Data
R-Excel Integration
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
R scatter plots
Py lecture5 python plots
Scala collection methods flatMap and flatten are more powerful than monadic f...

What's hot (18)

PDF
Pandas,scipy,numpy cheatsheet
PPT
Thesis PPT
PPTX
USE OF PRINT IN PYTHON PART 2
DOCX
Ecs40 winter 2017 homework 3
PDF
Matlab graphics
PDF
Essence of the iterator pattern
PDF
3 R Tutorial Data Structure
PPTX
Unit 11. Graphics
PDF
Type-level programming
PDF
Pandas pythonfordatascience
PPT
PDF
C++ ARRAY WITH EXAMPLES
PDF
R Data Visualization Tutorial: Bar Plots
PDF
R Programming: Numeric Functions In R
PDF
Monad Fact #2
PDF
Introduction to Data Science With R Lab Record
PDF
Data Visualization With R: Learn To Modify Color Of Plots
Pandas,scipy,numpy cheatsheet
Thesis PPT
USE OF PRINT IN PYTHON PART 2
Ecs40 winter 2017 homework 3
Matlab graphics
Essence of the iterator pattern
3 R Tutorial Data Structure
Unit 11. Graphics
Type-level programming
Pandas pythonfordatascience
C++ ARRAY WITH EXAMPLES
R Data Visualization Tutorial: Bar Plots
R Programming: Numeric Functions In R
Monad Fact #2
Introduction to Data Science With R Lab Record
Data Visualization With R: Learn To Modify Color Of Plots
Ad

Viewers also liked (7)

PPTX
PPT
People, places and communities
PPTX
PPTX
Building a sustainable society (green party)
PPTX
Den brittiska och amerikanska erfarenheten
PPTX
Radio frequencies
PPTX
Wave probigation
People, places and communities
Building a sustainable society (green party)
Den brittiska och amerikanska erfarenheten
Radio frequencies
Wave probigation
Ad

Similar to An introduction to matlab (20)

PPTX
R Programming.pptx
PDF
Python Programming Strings
PPTX
Ch no 4 Python Functions,Modules & packages.pptx
PPTX
Arrays 2d Arrays 2d Arrays 2d Arrrays 2d
PPT
Unit 3 arrays and_string
PPSX
DIWE - Advanced PHP Concepts
PPTX
statistical computation using R- an intro..
PPT
Client Side Programming with Applet
PPTX
Python Cheat Sheet Presentation Learning
DOCX
Introduction to r
PDF
Programming Fundamentals Arrays and Strings
ODP
Beginning Scala Svcc 2009
PPSX
Concepts of C [Module 2]
PDF
SVGo: a Go Library for SVG generation
PPTX
MatplotLib.pptx
PDF
Core c sharp and .net quick reference
PDF
Core csharp and net quick reference
PPTX
PPTX
R language introduction
PPTX
Python Programming.pptx
R Programming.pptx
Python Programming Strings
Ch no 4 Python Functions,Modules & packages.pptx
Arrays 2d Arrays 2d Arrays 2d Arrrays 2d
Unit 3 arrays and_string
DIWE - Advanced PHP Concepts
statistical computation using R- an intro..
Client Side Programming with Applet
Python Cheat Sheet Presentation Learning
Introduction to r
Programming Fundamentals Arrays and Strings
Beginning Scala Svcc 2009
Concepts of C [Module 2]
SVGo: a Go Library for SVG generation
MatplotLib.pptx
Core c sharp and .net quick reference
Core csharp and net quick reference
R language introduction
Python Programming.pptx

More from Dr. Andrew Wallace PhD (20)

PPTX
Sweden join nato
PPTX
Rearming russia
PPTX
PPTX
T 05 radio recivers
PPTX
R 06 radio frequencies
PPTX
T 02 components
PPTX
PPTX
T 01 electricity
PPTX
Amateur radio introduction
PPTX
PPTX
The law and log books
PPTX
Electrical safty
PPTX
Radio interference
PPTX
Test equipment
PPTX
Abbreviations and call signs
PPTX
Radio recivers
PPTX
Building a sustainable society (green party)
PPTX
Building a sustainable society
PPT
Technocracy For A Sustanalbe Soc Nov 2008
Sweden join nato
Rearming russia
T 05 radio recivers
R 06 radio frequencies
T 02 components
T 01 electricity
Amateur radio introduction
The law and log books
Electrical safty
Radio interference
Test equipment
Abbreviations and call signs
Radio recivers
Building a sustainable society (green party)
Building a sustainable society
Technocracy For A Sustanalbe Soc Nov 2008

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Pharma ospi slides which help in ospi learning
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Trump Administration's workforce development strategy
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
RMMM.pdf make it easy to upload and study
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Lesson notes of climatology university.
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Anesthesia in Laparoscopic Surgery in India
Microbial disease of the cardiovascular and lymphatic systems
Abdominal Access Techniques with Prof. Dr. R K Mishra
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Classroom Observation Tools for Teachers
Pharma ospi slides which help in ospi learning
O7-L3 Supply Chain Operations - ICLT Program
Module 4: Burden of Disease Tutorial Slides S2 2025
Final Presentation General Medicine 03-08-2024.pptx
Trump Administration's workforce development strategy
O5-L3 Freight Transport Ops (International) V1.pdf
Cell Structure & Organelles in detailed.
RMMM.pdf make it easy to upload and study
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Lesson notes of climatology university.
STATICS OF THE RIGID BODIES Hibbelers.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx

An introduction to matlab