SlideShare a Scribd company logo
Matlab: Procedures and Functions
Script filesScript files, also called M- files as they have extension .m, make MATLAB programming much more efficient than entering individual commands at the command prompt. A script file consists of MATLAB commands that together perform a specific task. The M-file is a text file which can be created and edited by any plain text editor like Notepad, emacs or the built-in MATLAB editor. 
Script filesScript files, also called M- files as they have extension .m, make MATLAB programming much more efficient than entering individual commands at the command prompt. A script file consists of MATLAB commands that together perform a specific task. The M-file is a text file which can be created and edited by any plain text editor like Notepad, emacs or the built-in MATLAB editor. 
Script filesHere’s an example of what a script file looks like:
Script filesImportant commands:for- To print "Hello World" 10 times writefor n=1:10
disp('Hello World')
 endScript filesImportant commands:if, else and else if-if a == b
a = b + 1
elseif a > b
 a = b - 1
else a = b
 end User Defined FunctionsWhen you use “sin” or “log” or “exp” in Matlab you are using “function m-files”. They are different from “script m-files” primarily because they have inputs and outputs. To specify which variables in the m-file are the inputs, and which are the outputs, the first line of the m-file should be in this form:			function output=function_name(input)
 User Defined FunctionsAn example of a function:
String HandlingCreating stringsStrings are matrices with character elements. The simplest way to create a string is to use it on the left side of an equal sign where the right side of the equal sign is an expression that evaluates to a string. String constants (literals) are enclosed in single quotes. The following example shows how to create string variables.>> first = 'John'; >> last = 'Coltrane'; >> name = [first,' ',last]
String Handling>> string='This is a string‘>> string(3) % gives the third element in the variable words. ans = i>> string(2)='t' % replaces the second element in the vector with t.
String Handling>> Y= input('Please type something here: ','s'); % Matlab expects a  number, string or a matrix from the keyboard. % The second argument says the returned variable should be a string.>> disp('The name is: '), disp(x) % gives text as output and the value of x.

More Related Content

PDF
Strings in c mrs.sowmya jyothi
PPTX
Chapter 2.datatypes and operators
PPTX
R programming Language
PPT
Linked list
PPTX
Introduction To Programming with Python-4
PPTX
linked list
PPTX
Data Structures in Python
DOCX
Strings in c mrs.sowmya jyothi
Chapter 2.datatypes and operators
R programming Language
Linked list
Introduction To Programming with Python-4
linked list
Data Structures in Python

What's hot (18)

PPT
Link List
PPT
Singly link list
PPT
Getting started with c++
PPT
Linked list
PDF
Programming with matlab session 3 notes
PPTX
Singly & Circular Linked list
PPTX
Pointers in c v5 12102017 1
PPTX
Strings
PPS
C programming session 09
PPTX
Circular link list.ppt
PPTX
Linked lists a
PPT
linked list
PDF
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
PDF
Doubly Link List
PPTX
Linear data structure concepts
PDF
Arrays in c_language
PDF
Arrays in c++
PPT
Strings
Link List
Singly link list
Getting started with c++
Linked list
Programming with matlab session 3 notes
Singly & Circular Linked list
Pointers in c v5 12102017 1
Strings
C programming session 09
Circular link list.ppt
Linked lists a
linked list
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
Doubly Link List
Linear data structure concepts
Arrays in c_language
Arrays in c++
Strings
Ad

Viewers also liked (20)

PPTX
Data Applied:Decision Trees
PPT
Excel Datamining Addin Intermediate
PPTX
MED dra Coding -MSSO
PPTX
RapidMiner: Advanced Processes And Operators
PPTX
Matlab Importing Data
PPTX
Control Statements in Matlab
PPT
Eugene SRTS Program
PPTX
LISP:Predicates in lisp
PPTX
MySql:Basics
PPTX
XL-MINER:Partition
PPT
2008 IEDM presentation
PPTX
MySql:Introduction
PPT
System Init
PPT
Festivals Refuerzo
ODP
Presentazione oroblu
PDF
Apresentação Red Advisers
PPTX
SPSS: Data Editor
PPTX
XL-Miner: Timeseries
PPTX
Data Applied: Developer Quicklook
PDF
Jive Clearspace Best#2598 C8
Data Applied:Decision Trees
Excel Datamining Addin Intermediate
MED dra Coding -MSSO
RapidMiner: Advanced Processes And Operators
Matlab Importing Data
Control Statements in Matlab
Eugene SRTS Program
LISP:Predicates in lisp
MySql:Basics
XL-MINER:Partition
2008 IEDM presentation
MySql:Introduction
System Init
Festivals Refuerzo
Presentazione oroblu
Apresentação Red Advisers
SPSS: Data Editor
XL-Miner: Timeseries
Data Applied: Developer Quicklook
Jive Clearspace Best#2598 C8
Ad

Similar to Procedures And Functions in Matlab (20)

PPTX
intro2matlab-basic knowledge about Matlab.pptx
PPTX
Chap2programing.pptxdxnDSnfkezjnfqjdsckjqds
PDF
Basics of programming in matlab for beginners
PPT
Matlab Basic Tutorial
PPTX
Introduction to matlab
PPT
Matlab Introduction
PDF
Introduction to matlab
PDF
Introduction to matlab
PPTX
Chap#0_Introducation_to_nsnsnnMATLAB.pptx
PPTX
Matlab ppt
PPTX
matlab presentation fro engninering students
PDF
Mit6 094 iap10_lec01
PDF
Matlab quickref
PPT
matlab tutorial with separate function description and handson learning
PPTX
1. Ch_1 SL_1_Intro to Matlab.pptx
PPT
Matlab1
PDF
Dsp lab _eec-652__vi_sem_18012013
PDF
Dsp lab _eec-652__vi_sem_18012013
PPTX
MATLAB for Engineers ME1006 (1 for beginer).pptx
intro2matlab-basic knowledge about Matlab.pptx
Chap2programing.pptxdxnDSnfkezjnfqjdsckjqds
Basics of programming in matlab for beginners
Matlab Basic Tutorial
Introduction to matlab
Matlab Introduction
Introduction to matlab
Introduction to matlab
Chap#0_Introducation_to_nsnsnnMATLAB.pptx
Matlab ppt
matlab presentation fro engninering students
Mit6 094 iap10_lec01
Matlab quickref
matlab tutorial with separate function description and handson learning
1. Ch_1 SL_1_Intro to Matlab.pptx
Matlab1
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
MATLAB for Engineers ME1006 (1 for beginer).pptx

More from DataminingTools Inc (20)

PPTX
Terminology Machine Learning
PPTX
Techniques Machine Learning
PPTX
Machine learning Introduction
PPTX
Areas of machine leanring
PPTX
AI: Planning and AI
PPTX
AI: Logic in AI 2
PPTX
AI: Logic in AI
PPTX
AI: Learning in AI 2
PPTX
AI: Learning in AI
PPTX
AI: Introduction to artificial intelligence
PPTX
AI: Belief Networks
PPTX
AI: AI & Searching
PPTX
AI: AI & Problem Solving
PPTX
Data Mining: Text and web mining
PPTX
Data Mining: Outlier analysis
PPTX
Data Mining: Mining stream time series and sequence data
PPTX
Data Mining: Mining ,associations, and correlations
PPTX
Data Mining: Graph mining and social network analysis
PPTX
Data warehouse and olap technology
PPTX
Data Mining: Data processing
Terminology Machine Learning
Techniques Machine Learning
Machine learning Introduction
Areas of machine leanring
AI: Planning and AI
AI: Logic in AI 2
AI: Logic in AI
AI: Learning in AI 2
AI: Learning in AI
AI: Introduction to artificial intelligence
AI: Belief Networks
AI: AI & Searching
AI: AI & Problem Solving
Data Mining: Text and web mining
Data Mining: Outlier analysis
Data Mining: Mining stream time series and sequence data
Data Mining: Mining ,associations, and correlations
Data Mining: Graph mining and social network analysis
Data warehouse and olap technology
Data Mining: Data processing

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Modernizing your data center with Dell and AMD
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
“AI and Expert System Decision Support & Business Intelligence Systems”
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Network Security Unit 5.pdf for BCA BBA.
Advanced methodologies resolving dimensionality complications for autism neur...
Dropbox Q2 2025 Financial Results & Investor Presentation
Approach and Philosophy of On baking technology
Encapsulation_ Review paper, used for researhc scholars
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Machine learning based COVID-19 study performance prediction
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Modernizing your data center with Dell and AMD
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Building Integrated photovoltaic BIPV_UPV.pdf
Unlocking AI with Model Context Protocol (MCP)

Procedures And Functions in Matlab

  • 2. Script filesScript files, also called M- files as they have extension .m, make MATLAB programming much more efficient than entering individual commands at the command prompt. A script file consists of MATLAB commands that together perform a specific task. The M-file is a text file which can be created and edited by any plain text editor like Notepad, emacs or the built-in MATLAB editor. 
  • 3. Script filesScript files, also called M- files as they have extension .m, make MATLAB programming much more efficient than entering individual commands at the command prompt. A script file consists of MATLAB commands that together perform a specific task. The M-file is a text file which can be created and edited by any plain text editor like Notepad, emacs or the built-in MATLAB editor. 
  • 4. Script filesHere’s an example of what a script file looks like:
  • 5. Script filesImportant commands:for- To print "Hello World" 10 times writefor n=1:10
  • 7. endScript filesImportant commands:if, else and else if-if a == b
  • 8. a = b + 1
  • 10. a = b - 1
  • 12. end User Defined FunctionsWhen you use “sin” or “log” or “exp” in Matlab you are using “function m-files”. They are different from “script m-files” primarily because they have inputs and outputs. To specify which variables in the m-file are the inputs, and which are the outputs, the first line of the m-file should be in this form: function output=function_name(input)
  • 13. User Defined FunctionsAn example of a function:
  • 14. String HandlingCreating stringsStrings are matrices with character elements. The simplest way to create a string is to use it on the left side of an equal sign where the right side of the equal sign is an expression that evaluates to a string. String constants (literals) are enclosed in single quotes. The following example shows how to create string variables.>> first = 'John'; >> last = 'Coltrane'; >> name = [first,' ',last]
  • 15. String Handling>> string='This is a string‘>> string(3) % gives the third element in the variable words. ans = i>> string(2)='t' % replaces the second element in the vector with t.
  • 16. String Handling>> Y= input('Please type something here: ','s'); % Matlab expects a number, string or a matrix from the keyboard. % The second argument says the returned variable should be a string.>> disp('The name is: '), disp(x) % gives text as output and the value of x.
  • 17. String HandlingAlso, different formats can be converted to ‘strings’ and vice verse. Here are some examples of functions that help in converting between different formats:int2str(n)  Converts an integer n to a stringhex2num(hstr)  Converts hexadecimal number hstr to a float.hex2dec(hstr)  Converts hexadecimal string to decimal integer.dec2hex(n)  Converts decimal integer to hexadecimal string. bin2dec(str)  Converts binary string to decimal integer. mat2str(A,n)  Convert a 2-D matrix to a string in MATLAB syntax.
  • 18. String HandlingThere are several functions available to manipulate or fetch appropriate data from strings:blanks(n)  Gives a string with n blanksdeblank(str)  Subtracts all blanks at the end of the string.lower(str)  All letters are changed to small.upper(str)  All letters are changed to capital.ischar(str)  If string contains character => gives 1 in return, 0 otherwise.
  • 19. String HandlingThere are several functions available to manipulate or fetch appropriate data from strings:isletter(str(i))  If element number i in the string is a letter=> gives one in return.isspace(str)  True for white space characters.strcmp(str1,str2)  returns 1 if strings S1 and S2 are the same and 0 otherwise.strcmpi(str1,str2)  returns 1 if strings S1 and S2 are the same except forcase and 0 otherwise.
  • 20. String HandlingThere are several functions available to manipulate or fetch appropriate data from strings:strfind(str1,str2)  returns the starting indices of any occurrences of the string str2 in the string str1.findstr(str1,str2)  returns the starting indices of any occurrences of the shorter of the two strings in the longer.
  • 21. Visit more self help tutorialsPick a tutorial of your choice and browse through it at your own pace.The tutorials section is free, self-guiding and will not involve any additional support.Visit us at www.dataminingtools.net