Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Prem MATLAB Notes

The document provides an introduction to MATLAB, covering its features, such as dynamic typing, matrix operations, and the main interface components like the command window and editor. It explains how to define variables, perform arithmetic operations, and create plots, as well as the types of files used in MATLAB. Additionally, it discusses matrix indexing, operations, and the basics of image processing with MATLAB.

Uploaded by

shamsnisar786
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Prem MATLAB Notes

The document provides an introduction to MATLAB, covering its features, such as dynamic typing, matrix operations, and the main interface components like the command window and editor. It explains how to define variables, perform arithmetic operations, and create plots, as well as the types of files used in MATLAB. Additionally, it discusses matrix indexing, operations, and the basics of image processing with MATLAB.

Uploaded by

shamsnisar786
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 53

Introduction to MATLAB

Dr. Prem Prakash Singh


Instructor: Sanja Fidler
MATLAB Guru
Prof. Rudra Pratap
Outline
1. Introduction
1. Overview
2. Variables
3. Matrix
4. Misc.
2. Image Processing with Matlab
3. References
What & Why
• Matrix Laboratory
– Dynamically typed language
• Variables require no declaration
• Creation by initialization (x=10;)
– All variables are treated as matrices
• Scalar: 1×1 matrix; Vector: N×1 or 1×N
matrix
• Calculations are much faster

• Advantages
– Fast implementation and debugging
– Natural matrix operation
– Powerful image processing toolbox
Matlab Main Screen
 Command Window
 Type and execute
commands
 Running programs
composed by user

 Current Directory
 View folders and m-
files

 Workspace
 View variables
 Double click on a
variable to see it in the
Array Editor

 Command History
 view past commands
 save a whole
Matlab Main Screen
 Editor Window
 For writing & editing
programs
 For creating script
files & function files
 Figure window
 Show graphs in result
of graphics command

 Help Window
 Contains information
for any features of
MATLAB
Input –Output in MATLAB
 Data Type -
 Fundamental data type is an Array
 No need to worry about data type or data object declarations

 Dimensioning
 Automatic in MATLAB
 No dimension statements are required

 Case sensitivity
 MATLAB is case sensitive.
 A and a are different variables.
 MATLAB commands and built-in function are typed in lower case.

 Output Display
 Output of every command is displayed on the unless MATLAB is directed
otherwise.
 A semicolon at the end of a command suppresses the screen output,
except for graphic and online help commands.
File type in MATLAB
 M-files
 .m extension
 Script files and function files

 Mat-files
 .mat extension
 Binary data files created by MATLAB and only MATLAB can read.
 It can be loaded into MATLAB with the load command.

 Fig-files
 .fig extension

 P-files
 .p extension

General commands
Outline
1. Introduction
1. Overview
2. Variables
3. Matrix
4. Misc.
2. Image Processing with Matlab
3. References
Variables
Defining variables

int >>a=1;
a; >>b=2+
a=1 4;
;
double
b; Matla
b=2+4; b
Variables are created when they are used
C/C++

All variables are created as matrices with “some” type


(unless specified)
Variables
a=
1;

b=
false;
Variables

Check if you can solve exercise at page 19


What you have learned
• How to do simple arithmetic calculations.
• How to assign values to variables
• How to suppress screen output
• How to control the appearance of floating point numbers on
the screen
• How to quit MATLAB
Variables
A = [1, 2,
3]

B=
[1,2,3;4,5,6]

C=[1 2 3;4 5 6;7 8


9]
Variables

C=[1 2 3;4 5 6;7 8


9]
C(2,3) = ?? Second row third 6
column

C(3,3) = 8 Element from third row third column


is changed to 8
C=

1 2 3
4 5 6
7 8 8
Variables

B=C(2:3, 1:3)
Get those elements of C that are
located in rows 2 & 3 and columns 1 to
3
B=

1 2 3
4 5 6
7 8 8
Variables
D=[1 ; 2 ;
3]

E=[1 2 3]’
Variables
Variables

Check if you can solve exercise at page 23


What you have learned
• How to create row and column vectors
• How to create a vector of n numbers linearly (equally) spaced
between two given numbers
• How to do simple arithmetic operations on vectors
• How to do array operations
• How to use trigonometric functions with array arguments
• How to use elementary math functions with array arguments
Creating simple plots
Creating simple plots

Check if you can solve exercise at page 27


What you have learned
• How to plot between two variables
• How to label the axes with text strings
• How to title the graph with a text string
• How to get a hard copy of the graph
Variables
C = ‘Hello World!';
Outline
1. Introduction
1. Overview
2. Variables
3. Matrix
4. Misc.
2. Image Processing with Matlab
3. References
Matrix Index
Matrix indices begin from 1 (not 0!!!)
Matrix indices must be positive integers

Column-Major
Order
Matrix Index
>> >> >> A(2,:)
A(2,2:3) A(2,1:end)
ans =
ans = ans =
4 5
5 4 5 6
6 >> A(:)
6
ans =

>> >> A(2,[1 1


A(2,1:2:3) 3]) 4
7
ans = ans = 2
5
4 6 4 6 8
3
6
9
Matrix Index
Accessing Elements
A = rand(4);
A(2,3)
A(:,2)
A(end,:)
A([1,2],[1,3])

A(1:2,3:end)
http://www.mathworks.com/company/newsletters/articles/matrix-indexing-
in-matlab.html
Matrix Operations
+ addition
- subtraction
* multiplication

^ power
‘ complex conjugate transpose
Matrix Operations

Given A and
B:

Addition Subtraction Product Transpose


Matrix Operations
.* element-wise
multiplication
./ element-wise division
.^element-wise power
Matrix Operations
A = [1 2 3; 5 1 4; 3 2 1]
A=
1 2 3
5 1 4
3 2 -1

x = A(1,:) y = A(3 ,:) b = x .* y c=x./y d=


x .^y
x= y= b= c= d=
1 2 3 4 - 3 8 0.33 -3 1 16 0.33
3 1 -3 0.5
Matrix Operations
Matrix Operations
What you have learned
• How to enter a matrix
• How to access an element, a row, a column
• How to multiply a matrix with vectors
• How to distinguish between array operation and matrix
operation
Matrix Operations
A/B Solve linear equation xA=B for x
A\B Solve linear equation Ax=B for x
Matrix Concatenation
X=[1 2], Y=[3
4]
Outline
1. Introduction
1. Overview
2. Variables
3. Matrix
4. Misc.
2. Image Processing with Matlab
3. References
Creating, saving and executing a
script file
Creating, saving and executing a
script file
Creating and executing a function
file
Creating and executing a function
file
Anonymous function
Anonymous function
Anonymous function
Symbolic Computation
Symbolic Computation
Symbolic Computation
Importing and exporting data
Importing and exporting data
Importing and exporting data
Thank you!

You might also like