SlideShare ist ein Scribd-Unternehmen logo
1 von 61
MATLAB
PROGRAMMING
An
introduction
Salient Features of MATLAB
MATLAB is a
powerful language
for technical
computing
The name MATLAB
stands for MATrix
LABoratory, because
its basic data
element is a matrix
(array).
It integrates
computation,
visualization, and
programming in an
easy-to-use
environment i.e.
Integrated
development
environment (IDE).
It has a very
extensive library of
predefined programs
or functions
designed to help
engineers and
scientists to solve
their problems in a
faster and less
painful way
There is no need for
memory management
It is platform-independent
A new program can be
developed easily using the
predefined functions
There is extensive graphics
support
Advantages of
Matlab
The MATLAB System
Development environment
Function Library
Application Program Interface (API)
Graphics system
SUBWINDOWS IN MATLAB DESKTOP
COMMAND WINDOW
CURRENT FOLDER
COMMAND HISTORY
WORKSPACE
MATLAB
WINDOWS
SNAPSHOT OF MATLAB DESKTOP
Command History window,
which displays all entries
made in the command window
during each session.
This window shows files and
directory available in the current
working directory of MATLAB
It is the window where we type commands, execute
programs, and launch other windows
This lists variables that you have either
entered or computed in your MATLAB
session
Matlab Basic numeric
Data types
Unsigned integer
(4 different classes)
Uint 8 Uint 16 Uint 32 Uint 64
Signed integer
(4 different classes)
Int 8 Int 16 Int 32 Int 64
Floating
point
data type
Double
precision
Single
precision
By default,
MAT LAB
stores all
numeric
values
as double-
precision
floating
point
numbers.
Arithmetic operators in matlab
Matlab relational operators
Built in constants
Abort In order to abort a command in MATLAB, hold down the
control key and press c to generate a local abort with MATLAB.
The Semicolon (;) If a semicolon (;) is typed at the end of a
command, the output of the command is not displayed.
Typing % When per cent symbol (%) is typed in the
beginning of a line, the line is designated as a comment.
When the enter key is pressed, the line is not executed.
SCRIPT FILES
A script file is a sequence
of MATLAB commands,
also called a program.
When a script file runs
(is executed), MATLAB
executes the commands
in the order.
When a script file has a
command that generates
an output, the output is
displayed in the
Command Window.
Using a script file is
convenient because it can
be edited and executed
many times.
Script files can be typed
and edited in any text
editor and then pasted
into the MATLAB editor.
Script files are also called
M-files because the
extension .m is used
when they are saved.
How to create a script
file
Matlab editor window
View of editor window
• In some cases variable is defined in the script file, and when the file
is executed, the user is prompted to assign a value to the variable in
the Command Window.
• This is done by using the input command for creating the variable.
• The form of input command that defines the characters that are
entered as a string
The input command
The disp command
• The disp command is used to display the
elements of a variable without displaying the
name of the variable, and to display text.
• Every time the disp command is executed, the
display it generates appears in a new line.
• The format of disp command is
The fprintf command can be used to display output
(text and data) on the screen.
With this command (unlike with the disp command)
the output can be formatted. For example, text and
numerical values of variables can be intermixed and
displayed in the same line.
The fprintf command
Different forms of
if construct
Three
Loops in
Matlab
For-end
loop
While-end
loop
In for-end loops the execution of a
command, or a group of commands, is
repeated a predetermined number of times
Each round of execution is called a pass.
Structure of a for-end loop
while-end loops are
used in situations when
looping is needed but
the number of passes is
not known in advance.
looping process carry
on until a specified
condition is satisfied.
Structure of while –end
loop
Example of for- end
loop
Result of example
Example of while - end
loop
Result of example
NESTED for LOOPS
A for loop can be nested within another for loop.
for k = 1 : 3
for n = 1 : 5
.
commands
.
end
end
Every time k is increased by 1 the
nested loop loops five times with
the value of n ranging from 1
through 5.
k = 1 n = 1 k = 2 n = 1 k = 3 n = 1
k = 1 n = 2 k = 2 n = 2 k = 3 n = 2
k = 1 n = 3 k = 2 n = 3 k = 3 n = 3
k = 1 n = 4 k = 2 n = 4 k = 3 n = 4
k = 1 n = 5 k = 2 n = 5 k = 3 n = 5
Overall the commands will be
executed 15 times with the values
of:
matrix = 0;
n = input('Enter the number of rows ');
m = input('Enter the number of columns ');
for i = 1:n
for j = 1:m
if i == j
matrix(i,j) = 1;
else
matrix(i,j) = 7;
end
end
end
disp('The matrix is:')
disp(matrix)
Nested
loop
>> Example2
Enter the number of rows 4
Enter the number of
columns 2
The matrix is:
1 7
7 1
7 7
7 7
Breaking out of loops 1
Example:
A = 6 B = 15
count = 1
while A > 0 & B < 10
A = A + 1
B = B + 2
count = count + 1
if count > 100
break
end
end
• Break out of the loop after 100 repetitions if the while
condition has not been met
Breaking out of loops 2
Breaking out of loops 3
Continuing of loops 1
Errors in Matlab
Syntax Errors
Runtime
Errors
Syntax errors
These errors mainly occur as a result of the
misspelling of variable or function names or from
missing quotes or parentheses.
Runtime errors are found by Matlab
during the execution of a program.
They are generally more difficult to fix
than simple syntax errors.
The capability to fix runtime errors is
something that improves with
experience only.
Run time
Errors
Debugging M-files
Debugging a
function file
Debugging a
script
Debugging a script file
Debugging step 1
run this code
(it is a program to display absolute values in
specified range)
Debugging Step2
fix the index bug
Run the code again
Step 3
Setting up a
break point
Step 4 Go to
Menu – debug -
absolute.m
To direct Matlab to run the command in line 1, click on the Step icon
Matlab runs the first line and then proceeds to line 2.
An alternative way to step through the program is by pressing the F10 key on the keyboard. Press
F10 to make Matlab run line 2 of the code.
Move the mouse and place the cursor directly over the variable x. A yellow box pops up and tells you the
values of x.
Press F10 to run line 3. Using the mouse, highlight the expression (x(k) > 0). Place the mouse cursor over
the highlighted area and right-click. Choose Copy from the Context Menu.
Press F10. The code steps to line 7. It should have entered the if statement and gone to line 5 to
change the sign of the first element, but it did not. Instead it went to line 7. By noting this, we can
discover that there is a programming error in the condition for the if statement. The greater than
character “>” should be changed to the less than character “<”.
Fix this bug by changing the character “>” to “<”. Then go to the Menu – Debug - Exit Debug Mode.
This terminates the debugger in Matlab.
The bug is now fixed. Remove the Breakpoint. This can be carried out by using the mouse. Left-click in
the space between the code and the line number 1 (pointed at by the arrow in the figure) to toggle the
Breakpoint to off. The red dot disappears.
Profiler
Let a Matlab program consists of a M-file that
may call a number of different Matlab
functions.
To find out the time that is required to execute
the script file and all the functions that it calls
,Matlab contains a tool that provides us with
this information ,called the Profiler.
Use this information to optimize our code and
make it run faster.
Matrix Methods for solving Linear
algebraic Equation
Cramer 's Method
Left
division
Rightdivision
Matlab for diploma students(1)
Matlab for diploma students(1)
Matlab for diploma students(1)

Weitere ähnliche Inhalte

Was ist angesagt?

Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionAmeen San
 
Basic matlab and matrix
Basic matlab and matrixBasic matlab and matrix
Basic matlab and matrixSaidur Rahman
 
How to work on Matlab.......
How to work on Matlab.......How to work on Matlab.......
How to work on Matlab.......biinoida
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programmingDamian T. Gordon
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABSarah Hussein
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab OverviiewNazim Naeem
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingDr. Manjunatha. P
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabSantosh V
 
Matlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IMatlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IVijay Kumar Gupta
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Randa Elanwar
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabTarun Gehlot
 

Was ist angesagt? (20)

Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab
MatlabMatlab
Matlab
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Basic matlab and matrix
Basic matlab and matrixBasic matlab and matrix
Basic matlab and matrix
 
C,C++ In Matlab
C,C++ In MatlabC,C++ In Matlab
C,C++ In Matlab
 
How to work on Matlab.......
How to work on Matlab.......How to work on Matlab.......
How to work on Matlab.......
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
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 INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab Overviiew
 
Seminar on MATLAB
Seminar on MATLABSeminar on MATLAB
Seminar on MATLAB
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processing
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab Workshop Presentation
Matlab Workshop PresentationMatlab Workshop Presentation
Matlab Workshop Presentation
 
Matlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IMatlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - I
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 

Andere mochten auch

Matlab intro
Matlab introMatlab intro
Matlab introfvijayami
 
Lecture 02 visualization and programming
Lecture 02   visualization and programmingLecture 02   visualization and programming
Lecture 02 visualization and programmingSmee Kaem Chann
 
Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06Aman kazmi
 
aem : Fourier series of Even and Odd Function
aem :  Fourier series of Even and Odd Functionaem :  Fourier series of Even and Odd Function
aem : Fourier series of Even and Odd FunctionSukhvinder Singh
 
MATLAB Based Vehicle Number Plate Identification System using OCR
MATLAB Based Vehicle Number Plate Identification System using OCRMATLAB Based Vehicle Number Plate Identification System using OCR
MATLAB Based Vehicle Number Plate Identification System using OCRGhanshyam Dusane
 
Licence plate recognition using matlab programming
Licence plate recognition using matlab programming Licence plate recognition using matlab programming
Licence plate recognition using matlab programming somchaturvedi
 
MATLAB Programs For Beginners. | Abhi Sharma
MATLAB Programs For Beginners. | Abhi SharmaMATLAB Programs For Beginners. | Abhi Sharma
MATLAB Programs For Beginners. | Abhi SharmaAbee Sharma
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islamIslam Alabbasy
 
Product and service design
Product and service designProduct and service design
Product and service designGrace Falcis
 

Andere mochten auch (12)

MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Lecture 02 visualization and programming
Lecture 02   visualization and programmingLecture 02   visualization and programming
Lecture 02 visualization and programming
 
Coursee
CourseeCoursee
Coursee
 
Mit6 094 iap10_lec01
Mit6 094 iap10_lec01Mit6 094 iap10_lec01
Mit6 094 iap10_lec01
 
Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06Lecture 19 matlab_script&function_files06
Lecture 19 matlab_script&function_files06
 
aem : Fourier series of Even and Odd Function
aem :  Fourier series of Even and Odd Functionaem :  Fourier series of Even and Odd Function
aem : Fourier series of Even and Odd Function
 
MATLAB Based Vehicle Number Plate Identification System using OCR
MATLAB Based Vehicle Number Plate Identification System using OCRMATLAB Based Vehicle Number Plate Identification System using OCR
MATLAB Based Vehicle Number Plate Identification System using OCR
 
Licence plate recognition using matlab programming
Licence plate recognition using matlab programming Licence plate recognition using matlab programming
Licence plate recognition using matlab programming
 
MATLAB Programs For Beginners. | Abhi Sharma
MATLAB Programs For Beginners. | Abhi SharmaMATLAB Programs For Beginners. | Abhi Sharma
MATLAB Programs For Beginners. | Abhi Sharma
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islam
 
Product and service design
Product and service designProduct and service design
Product and service design
 

Ähnlich wie Matlab for diploma students(1)

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
 
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
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabvikrammutneja1
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systemsRaghav Shetty
 
Handout2.pdf
Handout2.pdfHandout2.pdf
Handout2.pdfShoukat13
 
Matlab - Introduction and Basics
Matlab - Introduction and BasicsMatlab - Introduction and Basics
Matlab - Introduction and BasicsTechsparks
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab IntroductionDaniel Moore
 
Introduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfIntroduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfDrAzizulHasan1
 

Ähnlich wie Matlab for diploma students(1) (20)

Matlab-3.pptx
Matlab-3.pptxMatlab-3.pptx
Matlab-3.pptx
 
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
 
Matopt
MatoptMatopt
Matopt
 
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 tut2
Matlab tut2Matlab tut2
Matlab tut2
 
Matlab summary
Matlab summaryMatlab summary
Matlab summary
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systems
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
 
Handout2.pdf
Handout2.pdfHandout2.pdf
Handout2.pdf
 
matlabchapter1.ppt
matlabchapter1.pptmatlabchapter1.ppt
matlabchapter1.ppt
 
Matlab - Introduction and Basics
Matlab - Introduction and BasicsMatlab - Introduction and Basics
Matlab - Introduction and Basics
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
Ch1
Ch1Ch1
Ch1
 
Introduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfIntroduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdf
 
Matlab guide
Matlab guideMatlab guide
Matlab guide
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 

Mehr von Retheesh Raj

Boolean Algebra part 2 (1).pdf
Boolean Algebra part 2 (1).pdfBoolean Algebra part 2 (1).pdf
Boolean Algebra part 2 (1).pdfRetheesh Raj
 
boolean algebra part 4 (3).pdf
boolean algebra part 4 (3).pdfboolean algebra part 4 (3).pdf
boolean algebra part 4 (3).pdfRetheesh Raj
 
Boolean algebra part 3 [Autosaved] (1).pdf
Boolean algebra part 3 [Autosaved] (1).pdfBoolean algebra part 3 [Autosaved] (1).pdf
Boolean algebra part 3 [Autosaved] (1).pdfRetheesh Raj
 
Boolean Algebra part 5.pdf
Boolean Algebra part 5.pdfBoolean Algebra part 5.pdf
Boolean Algebra part 5.pdfRetheesh Raj
 
Ravi-KG College Pampady 28-2-23.ppt
Ravi-KG College Pampady 28-2-23.pptRavi-KG College Pampady 28-2-23.ppt
Ravi-KG College Pampady 28-2-23.pptRetheesh Raj
 
Jaya-National Science Day talk.pptx
Jaya-National Science Day talk.pptxJaya-National Science Day talk.pptx
Jaya-National Science Day talk.pptxRetheesh Raj
 

Mehr von Retheesh Raj (6)

Boolean Algebra part 2 (1).pdf
Boolean Algebra part 2 (1).pdfBoolean Algebra part 2 (1).pdf
Boolean Algebra part 2 (1).pdf
 
boolean algebra part 4 (3).pdf
boolean algebra part 4 (3).pdfboolean algebra part 4 (3).pdf
boolean algebra part 4 (3).pdf
 
Boolean algebra part 3 [Autosaved] (1).pdf
Boolean algebra part 3 [Autosaved] (1).pdfBoolean algebra part 3 [Autosaved] (1).pdf
Boolean algebra part 3 [Autosaved] (1).pdf
 
Boolean Algebra part 5.pdf
Boolean Algebra part 5.pdfBoolean Algebra part 5.pdf
Boolean Algebra part 5.pdf
 
Ravi-KG College Pampady 28-2-23.ppt
Ravi-KG College Pampady 28-2-23.pptRavi-KG College Pampady 28-2-23.ppt
Ravi-KG College Pampady 28-2-23.ppt
 
Jaya-National Science Day talk.pptx
Jaya-National Science Day talk.pptxJaya-National Science Day talk.pptx
Jaya-National Science Day talk.pptx
 

Kürzlich hochgeladen

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
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
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 

Kürzlich hochgeladen (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
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
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
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"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
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
 

Matlab for diploma students(1)

  • 2. Salient Features of MATLAB MATLAB is a powerful language for technical computing The name MATLAB stands for MATrix LABoratory, because its basic data element is a matrix (array). It integrates computation, visualization, and programming in an easy-to-use environment i.e. Integrated development environment (IDE). It has a very extensive library of predefined programs or functions designed to help engineers and scientists to solve their problems in a faster and less painful way
  • 3. There is no need for memory management It is platform-independent A new program can be developed easily using the predefined functions There is extensive graphics support Advantages of Matlab
  • 4. The MATLAB System Development environment Function Library Application Program Interface (API) Graphics system
  • 5. SUBWINDOWS IN MATLAB DESKTOP COMMAND WINDOW CURRENT FOLDER COMMAND HISTORY WORKSPACE MATLAB WINDOWS
  • 6. SNAPSHOT OF MATLAB DESKTOP Command History window, which displays all entries made in the command window during each session. This window shows files and directory available in the current working directory of MATLAB It is the window where we type commands, execute programs, and launch other windows This lists variables that you have either entered or computed in your MATLAB session
  • 7. Matlab Basic numeric Data types Unsigned integer (4 different classes) Uint 8 Uint 16 Uint 32 Uint 64 Signed integer (4 different classes) Int 8 Int 16 Int 32 Int 64
  • 8. Floating point data type Double precision Single precision By default, MAT LAB stores all numeric values as double- precision floating point numbers.
  • 12. Abort In order to abort a command in MATLAB, hold down the control key and press c to generate a local abort with MATLAB. The Semicolon (;) If a semicolon (;) is typed at the end of a command, the output of the command is not displayed. Typing % When per cent symbol (%) is typed in the beginning of a line, the line is designated as a comment. When the enter key is pressed, the line is not executed.
  • 13. SCRIPT FILES A script file is a sequence of MATLAB commands, also called a program. When a script file runs (is executed), MATLAB executes the commands in the order. When a script file has a command that generates an output, the output is displayed in the Command Window. Using a script file is convenient because it can be edited and executed many times. Script files can be typed and edited in any text editor and then pasted into the MATLAB editor. Script files are also called M-files because the extension .m is used when they are saved.
  • 14. How to create a script file
  • 16. View of editor window
  • 17. • In some cases variable is defined in the script file, and when the file is executed, the user is prompted to assign a value to the variable in the Command Window. • This is done by using the input command for creating the variable. • The form of input command that defines the characters that are entered as a string The input command
  • 18.
  • 19. The disp command • The disp command is used to display the elements of a variable without displaying the name of the variable, and to display text. • Every time the disp command is executed, the display it generates appears in a new line. • The format of disp command is
  • 20.
  • 21. The fprintf command can be used to display output (text and data) on the screen. With this command (unlike with the disp command) the output can be formatted. For example, text and numerical values of variables can be intermixed and displayed in the same line. The fprintf command
  • 22.
  • 23. Different forms of if construct Three
  • 24.
  • 26. In for-end loops the execution of a command, or a group of commands, is repeated a predetermined number of times Each round of execution is called a pass. Structure of a for-end loop
  • 27. while-end loops are used in situations when looping is needed but the number of passes is not known in advance. looping process carry on until a specified condition is satisfied. Structure of while –end loop
  • 28. Example of for- end loop Result of example Example of while - end loop Result of example
  • 29. NESTED for LOOPS A for loop can be nested within another for loop. for k = 1 : 3 for n = 1 : 5 . commands . end end Every time k is increased by 1 the nested loop loops five times with the value of n ranging from 1 through 5. k = 1 n = 1 k = 2 n = 1 k = 3 n = 1 k = 1 n = 2 k = 2 n = 2 k = 3 n = 2 k = 1 n = 3 k = 2 n = 3 k = 3 n = 3 k = 1 n = 4 k = 2 n = 4 k = 3 n = 4 k = 1 n = 5 k = 2 n = 5 k = 3 n = 5 Overall the commands will be executed 15 times with the values of:
  • 30. matrix = 0; n = input('Enter the number of rows '); m = input('Enter the number of columns '); for i = 1:n for j = 1:m if i == j matrix(i,j) = 1; else matrix(i,j) = 7; end end end disp('The matrix is:') disp(matrix) Nested loop >> Example2 Enter the number of rows 4 Enter the number of columns 2 The matrix is: 1 7 7 1 7 7 7 7
  • 31.
  • 32.
  • 33.
  • 34. Breaking out of loops 1 Example: A = 6 B = 15 count = 1 while A > 0 & B < 10 A = A + 1 B = B + 2 count = count + 1 if count > 100 break end end • Break out of the loop after 100 repetitions if the while condition has not been met
  • 35. Breaking out of loops 2
  • 36. Breaking out of loops 3
  • 38. Errors in Matlab Syntax Errors Runtime Errors
  • 39. Syntax errors These errors mainly occur as a result of the misspelling of variable or function names or from missing quotes or parentheses.
  • 40. Runtime errors are found by Matlab during the execution of a program. They are generally more difficult to fix than simple syntax errors. The capability to fix runtime errors is something that improves with experience only. Run time Errors
  • 41. Debugging M-files Debugging a function file Debugging a script
  • 42. Debugging a script file Debugging step 1 run this code (it is a program to display absolute values in specified range)
  • 43. Debugging Step2 fix the index bug Run the code again
  • 44. Step 3 Setting up a break point
  • 45. Step 4 Go to Menu – debug - absolute.m
  • 46.
  • 47.
  • 48. To direct Matlab to run the command in line 1, click on the Step icon Matlab runs the first line and then proceeds to line 2.
  • 49. An alternative way to step through the program is by pressing the F10 key on the keyboard. Press F10 to make Matlab run line 2 of the code.
  • 50. Move the mouse and place the cursor directly over the variable x. A yellow box pops up and tells you the values of x.
  • 51. Press F10 to run line 3. Using the mouse, highlight the expression (x(k) > 0). Place the mouse cursor over the highlighted area and right-click. Choose Copy from the Context Menu.
  • 52. Press F10. The code steps to line 7. It should have entered the if statement and gone to line 5 to change the sign of the first element, but it did not. Instead it went to line 7. By noting this, we can discover that there is a programming error in the condition for the if statement. The greater than character “>” should be changed to the less than character “<”.
  • 53. Fix this bug by changing the character “>” to “<”. Then go to the Menu – Debug - Exit Debug Mode. This terminates the debugger in Matlab.
  • 54. The bug is now fixed. Remove the Breakpoint. This can be carried out by using the mouse. Left-click in the space between the code and the line number 1 (pointed at by the arrow in the figure) to toggle the Breakpoint to off. The red dot disappears.
  • 55. Profiler Let a Matlab program consists of a M-file that may call a number of different Matlab functions. To find out the time that is required to execute the script file and all the functions that it calls ,Matlab contains a tool that provides us with this information ,called the Profiler. Use this information to optimize our code and make it run faster.
  • 56. Matrix Methods for solving Linear algebraic Equation Cramer 's Method