SlideShare a Scribd company logo
1 of 3
Download to read offline
http://www.tutorialspoint.com/matlab/matlab_syntax.htm Copyright © tutorialspoint.com
MATLAB - BASIC SYNTAX
MATLAB environment behaves like a super-complex calculator. Youcanenter commands at the >> command
prompt.
MATLAB is aninterpreted environment. Inother words, yougive a command and MATLAB executes it right
away.
Hands on Practice
Type a valid expression, for example,
5 + 5
And press ENTER
Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is:
ans = 10
Let us take up few more examples:
3 ^ 2 % 3 raised to the power of 2
Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is:
ans = 9
Another example,
sin(pi /2) % sine of angle 90o
Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is:
ans = 1
Another example,
7/0 % Divide by zero
Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is:
ans = Inf
warning: division by zero
Another example,
732 * 20.3
Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is:
ans = 1.4860e+04
MATLAB provides some specialexpressions for some mathematicalsymbols, like pifor π, Inf for ∞, i(and j) for
√-1 etc. Nan stands for 'not a number'.
Use of Semicolon (;) in MATLAB
Use of Semicolon (;) in MATLAB
Semicolon(;) indicates end of statement. However, if youwant to suppress and hide the MATLAB output for an
expression, add a semicolonafter the expression.
For example,
x = 3;
y = x + 5
Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is:
y = 8
Adding Comments
The percent symbol(%) is used for indicating a comment line. For example,
x = 9 % assign the value 9 to x
Youcanalso write a block of comments using the block comment operators % { and % }.
The MATLAB editor includes tools and context menuitems to help youadd, remove, or change the format of
comments.
Commonly used Operators and Special Characters
MATLAB supports the following commonly used operators and specialcharacters:
Operator Purpose
+ Plus; additionoperator.
- Minus; subtractionoperator.
* Scalar and matrix multiplicationoperator.
.* Array multiplicationoperator.
^ Scalar and matrix exponentiationoperator.
.^ Array exponentiationoperator.
 Left-divisionoperator.
/ Right-divisionoperator.
. Array left-divisionoperator.
./ Array right-divisionoperator.
: Colon; generates regularly spaced elements and represents anentire row or
column.
( ) Parentheses; encloses functionarguments and array indices; overrides
precedence.
[ ] Brackets; enclosures array elements.
. Decimalpoint.
… Ellipsis; line-continuationoperator
, Comma; separates statements and elements ina row
; Semicolon; separates columns and suppresses display.
% Percent sign; designates a comment and specifies formatting.
_ Quote signand transpose operator.
._ Nonconjugated transpose operator.
= Assignment operator.
Special Variables and Constants
MATLAB supports the following specialvariables and constants:
Name Meaning
ans Most recent answer.
eps Accuracy of floating-point precision.
i,j The imaginary unit √-1.
Inf Infinity.
NaN Undefined numericalresult (not a number).
pi The number π
Naming Variables
Variable names consist of a letter followed by any number of letters, digits or underscore.
MATLAB is case-sensitive.
Variable names canbe of any length, however, MATLAB uses only first N characters, where N is givenby the
functionnamelengthmax.
Saving Your Work
The save command is used for saving allthe variables inthe workspace, as a file with.mat extension, inthe
current directory.
For example,
save myfile
Youcanreload the file anytime later using the load command.
load myfile

More Related Content

What's hot

Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Shameer Ahmed Koya
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlabTUOS-Sam
 
Comp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codeComp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codepradesigali1
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators pptViraj Shah
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkreddyprasad reddyvari
 
Scilab as a calculator
Scilab as a calculatorScilab as a calculator
Scilab as a calculatorScilab
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABRavikiran A
 
Please look at the problems I am having which are listed below: Write a prog...
Please look at the problems I am having which are listed below:  Write a prog...Please look at the problems I am having which are listed below:  Write a prog...
Please look at the problems I am having which are listed below: Write a prog...licservernoida
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)harman kaur
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Abou Bakr Ashraf
 
Programming Environment in Matlab
Programming Environment in MatlabProgramming Environment in Matlab
Programming Environment in MatlabDataminingTools Inc
 
Excel IF function
Excel IF functionExcel IF function
Excel IF functionHtay Aung
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsdishti7
 

What's hot (18)

Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlab
 
Comp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source codeComp 122 lab 6 lab report and source code
Comp 122 lab 6 lab report and source code
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
 
Matlab Script - Loop Control
Matlab Script - Loop ControlMatlab Script - Loop Control
Matlab Script - Loop Control
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
 
Using matlab simulink
Using matlab simulinkUsing matlab simulink
Using matlab simulink
 
Scilab as a calculator
Scilab as a calculatorScilab as a calculator
Scilab as a calculator
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Please look at the problems I am having which are listed below: Write a prog...
Please look at the problems I am having which are listed below:  Write a prog...Please look at the problems I am having which are listed below:  Write a prog...
Please look at the problems I am having which are listed below: Write a prog...
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
 
Matlab summary
Matlab summaryMatlab summary
Matlab summary
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
 
Programming Environment in Matlab
Programming Environment in MatlabProgramming Environment in Matlab
Programming Environment in Matlab
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
Excel IF function
Excel IF functionExcel IF function
Excel IF function
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 

Similar to Matlab syntax

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 beyondMahuaPal6
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsMukesh Kumar
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionAmeen San
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1Elaf A.Saeed
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlabaman gupta
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systemsRaghav Shetty
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013amanabr
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Kurmendra Singh
 
MATLAB BASICS
MATLAB BASICSMATLAB BASICS
MATLAB BASICSbutest
 
Brief Introduction to Matlab
Brief  Introduction to MatlabBrief  Introduction to Matlab
Brief Introduction to MatlabTariq kanher
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docx
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docxMATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docx
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docxandreecapon
 

Similar to Matlab syntax (20)

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
MatlabMatlab
Matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
Ch1
Ch1Ch1
Ch1
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Matlab guide
Matlab guideMatlab guide
Matlab guide
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systems
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
MATLAB BASICS
MATLAB BASICSMATLAB BASICS
MATLAB BASICS
 
Brief Introduction to Matlab
Brief  Introduction to MatlabBrief  Introduction to Matlab
Brief Introduction to Matlab
 
Basic matlab for beginners
Basic matlab for beginnersBasic matlab for beginners
Basic matlab for beginners
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docx
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docxMATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docx
MATLAB sessions Laboratory 1MAT 275 Laboratory 1Introdu.docx
 
Matlab Manual
Matlab ManualMatlab Manual
Matlab Manual
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 

More from pramodkumar1804 (20)

Matlab strings
Matlab stringsMatlab strings
Matlab strings
 
Matlab simulink
Matlab simulinkMatlab simulink
Matlab simulink
 
Matlab polynomials
Matlab polynomialsMatlab polynomials
Matlab polynomials
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Matlab overview 3
Matlab overview 3Matlab overview 3
Matlab overview 3
 
Matlab overview 2
Matlab overview 2Matlab overview 2
Matlab overview 2
 
Matlab overview
Matlab overviewMatlab overview
Matlab overview
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Matlab numbers
Matlab numbersMatlab numbers
Matlab numbers
 
Matlab matrics
Matlab matricsMatlab matrics
Matlab matrics
 
Matlab m files
Matlab m filesMatlab m files
Matlab m files
 
Matlab loops 2
Matlab loops 2Matlab loops 2
Matlab loops 2
 
Matlab loops
Matlab loopsMatlab loops
Matlab loops
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 
Matlab gnu octave
Matlab gnu octaveMatlab gnu octave
Matlab gnu octave
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 
Matlab differential
Matlab differentialMatlab differential
Matlab differential
 
Matlab decisions
Matlab decisionsMatlab decisions
Matlab decisions
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

Matlab syntax

  • 1. http://www.tutorialspoint.com/matlab/matlab_syntax.htm Copyright © tutorialspoint.com MATLAB - BASIC SYNTAX MATLAB environment behaves like a super-complex calculator. Youcanenter commands at the >> command prompt. MATLAB is aninterpreted environment. Inother words, yougive a command and MATLAB executes it right away. Hands on Practice Type a valid expression, for example, 5 + 5 And press ENTER Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is: ans = 10 Let us take up few more examples: 3 ^ 2 % 3 raised to the power of 2 Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is: ans = 9 Another example, sin(pi /2) % sine of angle 90o Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is: ans = 1 Another example, 7/0 % Divide by zero Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is: ans = Inf warning: division by zero Another example, 732 * 20.3 Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is: ans = 1.4860e+04 MATLAB provides some specialexpressions for some mathematicalsymbols, like pifor π, Inf for ∞, i(and j) for √-1 etc. Nan stands for 'not a number'. Use of Semicolon (;) in MATLAB
  • 2. Use of Semicolon (;) in MATLAB Semicolon(;) indicates end of statement. However, if youwant to suppress and hide the MATLAB output for an expression, add a semicolonafter the expression. For example, x = 3; y = x + 5 Whenyouclick the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is: y = 8 Adding Comments The percent symbol(%) is used for indicating a comment line. For example, x = 9 % assign the value 9 to x Youcanalso write a block of comments using the block comment operators % { and % }. The MATLAB editor includes tools and context menuitems to help youadd, remove, or change the format of comments. Commonly used Operators and Special Characters MATLAB supports the following commonly used operators and specialcharacters: Operator Purpose + Plus; additionoperator. - Minus; subtractionoperator. * Scalar and matrix multiplicationoperator. .* Array multiplicationoperator. ^ Scalar and matrix exponentiationoperator. .^ Array exponentiationoperator. Left-divisionoperator. / Right-divisionoperator. . Array left-divisionoperator. ./ Array right-divisionoperator. : Colon; generates regularly spaced elements and represents anentire row or column. ( ) Parentheses; encloses functionarguments and array indices; overrides precedence. [ ] Brackets; enclosures array elements. . Decimalpoint. … Ellipsis; line-continuationoperator , Comma; separates statements and elements ina row
  • 3. ; Semicolon; separates columns and suppresses display. % Percent sign; designates a comment and specifies formatting. _ Quote signand transpose operator. ._ Nonconjugated transpose operator. = Assignment operator. Special Variables and Constants MATLAB supports the following specialvariables and constants: Name Meaning ans Most recent answer. eps Accuracy of floating-point precision. i,j The imaginary unit √-1. Inf Infinity. NaN Undefined numericalresult (not a number). pi The number π Naming Variables Variable names consist of a letter followed by any number of letters, digits or underscore. MATLAB is case-sensitive. Variable names canbe of any length, however, MATLAB uses only first N characters, where N is givenby the functionnamelengthmax. Saving Your Work The save command is used for saving allthe variables inthe workspace, as a file with.mat extension, inthe current directory. For example, save myfile Youcanreload the file anytime later using the load command. load myfile