SlideShare a Scribd company logo
About :
 Arrays , Matlab operator
 Graphics
 Fundamentals Simulink
 Data visualization
Presented by:
 ADITYA CHOUDHURY
 140101ecr021
Arrays:
Arrays and Matrix Operations:
1) >> [1, 3, 5; 2, 4, 6; 7, 7, 7] 3) >> A = zeros(2, 4 )
ans = 1 3 5 A = 0 0 0 0
2 4 6 0 0 0 0
7 7 7
2) >>A = zeros(2) 4) >> A = ones(3, 2)
A = 0 0 A = 1 1
0 0 1 1
1 1
5) >> A = rand(2,5) 7) >> eye(4,3)
A = 0.9501 0.6068 0.8913 0.4565 0.8214 ans = 1 0 0
0.2311 0.4860 0.7621 0.0185 0.4447 0 1 0
• 0 0 1
6) >> eye(3) 0 0 0
ans = 1 0 0 8) A = eye(3,4,5)
0 1 0 ??? Error using ==> eye
0 0 1 Too many input arguments.
Accessing Elements of an Array:
ex: >> A = [1 3 5; 2 4 6; 3 5 7]
1 3 5
2 4 6
3 5 7
>> A(2,3)
ans =6
>> A(1:2:9)
ans = 1 5 4 5 3 7
>> A(2,:)
ans = 2 4 6
Expanding the Size of an Array:
1) >> A = [3 5 7] 3) >> A = [3 5 7];
A = 3 5 7 >> B = [2 4];
>> A = [A 9] >> C = [A; B]
A = 3 5 7 9 ??? Error using
*All rows in the bracketed expression must have the same number of columns
2)>> A = [3 5 7];
>> B = [1 3 5];
>> C = [A; B]
C = 3 5 7
1 3 5
Deleting Array Element:
>> A = [3 5 7];
>> A(2) = []
A = 3 7
>> A = [1 3 5; 2 4 6]
A = 1 3 5
2 4 6
>> A(2,3) = []
??? Indexed empty matrix assignment is not allowed
>> A = [1 3 5; 2 4 6]
A = 1 3 5
2 4 6 >> A(2,:) = [] A = 1 3 5
You cannot remove a single
element from a multidimensional
array, since the array would no
longer be conforman
Array Addition:
A = [1 3 5] and B = [10 12 14]
[A(1) + B(1) A(2) + B(2) A(3) + B(3)] = [11 15 19]
>> C = [1,3,5]
C = 1 3 5
>> D = [2,4,6;3,5,7]
D = 2 4 6
3 5 7
>> C + D
??? Error using ==> +
Matrix dimensions must agree.
Array Right Division:
>> A = [2, 4, 6] A = 2 4 6
>> B = [2, 2, 2] B = 2 2 2
>> A./B ans = 1 2 3
Array Left Division:
>> A.B
ans = 1.0000 0.5000 0.3333
Array Exponentiation:
>> A = [2, 3, 4] A = 2 3 4
>> B = [3, 2, 0.5] B = 3.0000 2.0000 0.5000
>> A.^B ans = 8 9 2
UNARY MATRIX OPERATIONS: *Assume matrix A for example
Transpose: A'
Determinant: det(A)
Inverse: inv(A)
Matrix Exponentiation: A^2
ARRAY FUNCTIONS:
Ndims: A = ones(2,3,2); >> ndims(A) ans = 3 *NOTE
Size: >> A = zeros(2,3,2,4); >> size(A) ans = 2 3 2 4
Diag: >> A = [1 3 5; 2 4 6; 0 2 4] >> diag(A) ans = 1
4
4
>> diag(A,1)
ans = 3
6
>> diag(A,-1)
ans = 2
2
The size
function
returns the
length of each
dimension
Length: >> A = [1 3; 2 4; 0 2]; >> length(A) ans = 3 Note:
sort :>> A = [4 2 3 9 1 2]; >> sort(A) ans = 1 2 2 3 4 9
>> A = [5 0 4; 2 2 1] A = 5 0 4
2 2 1
>> sort(A) ans = 2 0 1
5 2 4
>> A = [5 0 4; 2 2 1] A = 5 0 4
2 2 1
>> sort(A,2)
ans = 0 4 5
1 2 2
The length function returns the
length of the largest dimension
of an array
Relational operators: logical operators:
Equality ==
Not equal ~=
>
<
>=
<=
Element-wise:
AND, OR, and NOT.
&, |, and ~
Short-circuit
AND and OR.
&& and ||
clc
clear all
close all
x=[5 6 9 2]
y=[3 5 6 2]
less=x<y
lesseq=x<=y
greater=x>y
greatereq=x>=y
equal=x==y
notequal=x~=y
output:
x = 5 6 9 2
y = 3 5 6 2
less = 0 0 0 0
lesseq = 0 0 0 1
greater = 1 1 1 0
greatereq = 1 1 1 1
equal = 0 0 0 1
notequal = 1 1 1 0
clc
clear all
close all
x=[0 0 1 1]
y=[0 1 0 1]
andgate= (x>=1)&(y>=1)
orgate= (x>=1)|(y>=1)
nandgate=~((x>=1)&(y>=1))
norgate= ~((x>=1)|(y>=1))
output:
x = 0 0 1 1
y = 0 1 0 1
andgate = 0 0 0 1
orgate = 0 1 1 1
nandgate = 1 1 1 0
norgate = 1 0 0 0
2D Plots: You can use functions such as
plot
stem
polar
Compass
Loglog
semilogx
semilogy
area
fill
pie ,hist, stairs
x = -1 : 0.1 : 1.5;
y1 = cos(x);
y2 = x.^2 - 1;
plot(x, y1, 'b', x, y2, 'r.-')
title('Two 2D Plots in the same Window')
legend('y_1 = cos(x)', 'y_2 = x^2 - 1')
xlabel('x')
ylabel('y')
Subplot: display multiple plots in the same window
Multiple Graphs :
Plotting Specifiers:
Specifier LineStyle
'-' Solid line (default)
'--' Dashed line
':' Dotted line
'-.' Dash-dot line
Specifier Color
r Red
g Green
b Blue
c Cyan
m Magenta
y Yellow
k Black
w White
3D Plot:
You can use functions such as:
mesh – Draw mesh plot (wireframe)
surf – Draw shaded mesh plots
contour – Draw contour plots
plot3 – 3-D Line plot
U = -5 : 0.2 : 5;
V = -6 : 0.2 : 6;
[x, y] = meshgrid(U, V);
z = cos(x) .* cos(y) .* exp(-sqrt(x.^2 + y.^2) / 20);
surf(x, y, z)
Printing and Saving:
print Print figure or save to specific file format
saveas Save figure to specific file format
getframe Capture axes or figure as movie frame
savefig Save figure and contents to FIG-file
openfig Open figure saved in FIG-file
orient Paper orientation for printing or saving
hgexport Export figure
printopt Configure printer defaults
Simulink:
INTRODUCTION
• The Matlab software contain a program known as Simulink.
• The Simulink is taken form the word Simulation which means to represent a
system using another system that has identical behavior or characteristics to real
world system.
• The Simulink program is used for the formation various models graphically.
MATLAB ARRAYS
MATLAB ARRAYS
MATLAB ARRAYS
Thank you…

More Related Content

PPTX
Piecewise functions
PDF
Inequations and finding rule
PDF
matlab example
PDF
Trial terengganu 2014 spm add math k2 skema
PPT
Piecewise functions updated_2016
PPT
Gr10 piecewise functions
PPT
Review Sheet B Substitution And Solving Inequalities
PDF
Piecewise functions
Inequations and finding rule
matlab example
Trial terengganu 2014 spm add math k2 skema
Piecewise functions updated_2016
Gr10 piecewise functions
Review Sheet B Substitution And Solving Inequalities

What's hot (20)

DOC
Exponent and power By expert's class ahmedabad
PDF
Support Vector Machines
PDF
Igraph
PDF
Single page-integral-table
PDF
PPTX
Introduction to matlab lecture 4 of 4
PDF
Single page-integral-table
PPT
Piecewise Functions
PDF
Trial terengganu 2014 spm add math k1 skema [scan]
PDF
Integration formulas
PPTX
BRESENHAM’S LINE DRAWING ALGORITHM
PDF
Algebraic identities
PPTX
2D Plot Matlab
PDF
Integral table
PDF
Integral table
PPTX
Making t chart
PDF
Laws of Exponent
PPTX
Complex Numbers Mathmatics N4
PDF
Examens math
PPT
Math Section 2.2 ECC Etudes
Exponent and power By expert's class ahmedabad
Support Vector Machines
Igraph
Single page-integral-table
Introduction to matlab lecture 4 of 4
Single page-integral-table
Piecewise Functions
Trial terengganu 2014 spm add math k1 skema [scan]
Integration formulas
BRESENHAM’S LINE DRAWING ALGORITHM
Algebraic identities
2D Plot Matlab
Integral table
Integral table
Making t chart
Laws of Exponent
Complex Numbers Mathmatics N4
Examens math
Math Section 2.2 ECC Etudes
Ad

Similar to MATLAB ARRAYS (20)

PPTX
MATLAB - Arrays and Matrices
PDF
Introduction to matlab chapter2 by Dr.Bashir m. sa'ad.pdf
PPTX
Matlab-1.pptx
PPT
Matlab Tutorial.ppt
PPTX
An Introduction to MATLAB for beginners
PDF
PDF
Basic concepts in_matlab
PDF
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
PDF
Matlabch01
PDF
ML-CheatSheet (1).pdf
PPT
ArrayBasics.ppt
PPT
matlab_tutorial.ppt
PPT
matlab_tutorial.ppt
PPT
matlab_tutorial.ppt
PPTX
presentation.pptx
PDF
Matlab pt1
PDF
Advanced MATLAB Tutorial for Engineers & Scientists
PPT
matlab tutorial with separate function description and handson learning
PPTX
INTRODUCTION TO MATLAB presentation.pptx
PPTX
Introduction to MATLAB Programming for Engineers
MATLAB - Arrays and Matrices
Introduction to matlab chapter2 by Dr.Bashir m. sa'ad.pdf
Matlab-1.pptx
Matlab Tutorial.ppt
An Introduction to MATLAB for beginners
Basic concepts in_matlab
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
Matlabch01
ML-CheatSheet (1).pdf
ArrayBasics.ppt
matlab_tutorial.ppt
matlab_tutorial.ppt
matlab_tutorial.ppt
presentation.pptx
Matlab pt1
Advanced MATLAB Tutorial for Engineers & Scientists
matlab tutorial with separate function description and handson learning
INTRODUCTION TO MATLAB presentation.pptx
Introduction to MATLAB Programming for Engineers
Ad

Recently uploaded (20)

DOCX
573137875-Attendance-Management-System-original
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPT
Project quality management in manufacturing
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Well-logging-methods_new................
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
Welding lecture in detail for understanding
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Geodesy 1.pptx...............................................
573137875-Attendance-Management-System-original
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
CH1 Production IntroductoryConcepts.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Project quality management in manufacturing
bas. eng. economics group 4 presentation 1.pptx
Digital Logic Computer Design lecture notes
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
R24 SURVEYING LAB MANUAL for civil enggi
Well-logging-methods_new................
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Welding lecture in detail for understanding
Model Code of Practice - Construction Work - 21102022 .pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Geodesy 1.pptx...............................................

MATLAB ARRAYS

  • 1. About :  Arrays , Matlab operator  Graphics  Fundamentals Simulink  Data visualization Presented by:  ADITYA CHOUDHURY  140101ecr021
  • 2. Arrays: Arrays and Matrix Operations: 1) >> [1, 3, 5; 2, 4, 6; 7, 7, 7] 3) >> A = zeros(2, 4 ) ans = 1 3 5 A = 0 0 0 0 2 4 6 0 0 0 0 7 7 7 2) >>A = zeros(2) 4) >> A = ones(3, 2) A = 0 0 A = 1 1 0 0 1 1 1 1
  • 3. 5) >> A = rand(2,5) 7) >> eye(4,3) A = 0.9501 0.6068 0.8913 0.4565 0.8214 ans = 1 0 0 0.2311 0.4860 0.7621 0.0185 0.4447 0 1 0 • 0 0 1 6) >> eye(3) 0 0 0 ans = 1 0 0 8) A = eye(3,4,5) 0 1 0 ??? Error using ==> eye 0 0 1 Too many input arguments.
  • 4. Accessing Elements of an Array: ex: >> A = [1 3 5; 2 4 6; 3 5 7] 1 3 5 2 4 6 3 5 7 >> A(2,3) ans =6 >> A(1:2:9) ans = 1 5 4 5 3 7 >> A(2,:) ans = 2 4 6
  • 5. Expanding the Size of an Array: 1) >> A = [3 5 7] 3) >> A = [3 5 7]; A = 3 5 7 >> B = [2 4]; >> A = [A 9] >> C = [A; B] A = 3 5 7 9 ??? Error using *All rows in the bracketed expression must have the same number of columns 2)>> A = [3 5 7]; >> B = [1 3 5]; >> C = [A; B] C = 3 5 7 1 3 5
  • 6. Deleting Array Element: >> A = [3 5 7]; >> A(2) = [] A = 3 7 >> A = [1 3 5; 2 4 6] A = 1 3 5 2 4 6 >> A(2,3) = [] ??? Indexed empty matrix assignment is not allowed >> A = [1 3 5; 2 4 6] A = 1 3 5 2 4 6 >> A(2,:) = [] A = 1 3 5 You cannot remove a single element from a multidimensional array, since the array would no longer be conforman
  • 7. Array Addition: A = [1 3 5] and B = [10 12 14] [A(1) + B(1) A(2) + B(2) A(3) + B(3)] = [11 15 19] >> C = [1,3,5] C = 1 3 5 >> D = [2,4,6;3,5,7] D = 2 4 6 3 5 7 >> C + D ??? Error using ==> + Matrix dimensions must agree.
  • 8. Array Right Division: >> A = [2, 4, 6] A = 2 4 6 >> B = [2, 2, 2] B = 2 2 2 >> A./B ans = 1 2 3 Array Left Division: >> A.B ans = 1.0000 0.5000 0.3333 Array Exponentiation: >> A = [2, 3, 4] A = 2 3 4 >> B = [3, 2, 0.5] B = 3.0000 2.0000 0.5000 >> A.^B ans = 8 9 2
  • 9. UNARY MATRIX OPERATIONS: *Assume matrix A for example Transpose: A' Determinant: det(A) Inverse: inv(A) Matrix Exponentiation: A^2 ARRAY FUNCTIONS: Ndims: A = ones(2,3,2); >> ndims(A) ans = 3 *NOTE Size: >> A = zeros(2,3,2,4); >> size(A) ans = 2 3 2 4 Diag: >> A = [1 3 5; 2 4 6; 0 2 4] >> diag(A) ans = 1 4 4 >> diag(A,1) ans = 3 6 >> diag(A,-1) ans = 2 2 The size function returns the length of each dimension
  • 10. Length: >> A = [1 3; 2 4; 0 2]; >> length(A) ans = 3 Note: sort :>> A = [4 2 3 9 1 2]; >> sort(A) ans = 1 2 2 3 4 9 >> A = [5 0 4; 2 2 1] A = 5 0 4 2 2 1 >> sort(A) ans = 2 0 1 5 2 4 >> A = [5 0 4; 2 2 1] A = 5 0 4 2 2 1 >> sort(A,2) ans = 0 4 5 1 2 2 The length function returns the length of the largest dimension of an array
  • 11. Relational operators: logical operators: Equality == Not equal ~= > < >= <= Element-wise: AND, OR, and NOT. &, |, and ~ Short-circuit AND and OR. && and ||
  • 12. clc clear all close all x=[5 6 9 2] y=[3 5 6 2] less=x<y lesseq=x<=y greater=x>y greatereq=x>=y equal=x==y notequal=x~=y output: x = 5 6 9 2 y = 3 5 6 2 less = 0 0 0 0 lesseq = 0 0 0 1 greater = 1 1 1 0 greatereq = 1 1 1 1 equal = 0 0 0 1 notequal = 1 1 1 0 clc clear all close all x=[0 0 1 1] y=[0 1 0 1] andgate= (x>=1)&(y>=1) orgate= (x>=1)|(y>=1) nandgate=~((x>=1)&(y>=1)) norgate= ~((x>=1)|(y>=1)) output: x = 0 0 1 1 y = 0 1 0 1 andgate = 0 0 0 1 orgate = 0 1 1 1 nandgate = 1 1 1 0 norgate = 1 0 0 0
  • 13. 2D Plots: You can use functions such as plot stem polar Compass Loglog semilogx semilogy area fill pie ,hist, stairs x = -1 : 0.1 : 1.5; y1 = cos(x); y2 = x.^2 - 1; plot(x, y1, 'b', x, y2, 'r.-') title('Two 2D Plots in the same Window') legend('y_1 = cos(x)', 'y_2 = x^2 - 1') xlabel('x') ylabel('y')
  • 14. Subplot: display multiple plots in the same window Multiple Graphs :
  • 15. Plotting Specifiers: Specifier LineStyle '-' Solid line (default) '--' Dashed line ':' Dotted line '-.' Dash-dot line Specifier Color r Red g Green b Blue c Cyan m Magenta y Yellow k Black w White
  • 16. 3D Plot: You can use functions such as: mesh – Draw mesh plot (wireframe) surf – Draw shaded mesh plots contour – Draw contour plots plot3 – 3-D Line plot U = -5 : 0.2 : 5; V = -6 : 0.2 : 6; [x, y] = meshgrid(U, V); z = cos(x) .* cos(y) .* exp(-sqrt(x.^2 + y.^2) / 20); surf(x, y, z)
  • 17. Printing and Saving: print Print figure or save to specific file format saveas Save figure to specific file format getframe Capture axes or figure as movie frame savefig Save figure and contents to FIG-file openfig Open figure saved in FIG-file orient Paper orientation for printing or saving hgexport Export figure printopt Configure printer defaults
  • 18. Simulink: INTRODUCTION • The Matlab software contain a program known as Simulink. • The Simulink is taken form the word Simulation which means to represent a system using another system that has identical behavior or characteristics to real world system. • The Simulink program is used for the formation various models graphically.