E N D
Introduction to MATLAB Presented By Narendra L Lokhande Department of Electronics and Telecommunication R C Patel Institute of Technology, Shirpur, Dist: Dhule, Maharashtra Email: narenlokhande@gmail.com
History of MATLAB • Invented by Cleve Moler in late 1970s to give students access to LINPACK (Linear) and EISPACK (Eigen values) without having to learn Fortran. • MATLAB developed as an interactive system to access LINPACK and EISPACK • MATLAB developed as an interactive system to access LINPACK and EISPACK • In the 1980’s, MATLAB was rewritten in C with more functionality (such as plotting routines) • Together with Jack Little and Steve Bangert they founded Mathworks in 1984 and created MATLAB. • The Mathworks is now responsible for development, sale, and support for MATLAB • Interpreted-code based system in which the fundamental element is a matrix. • MATLAB stands for MATrixLABoratory
Strengths of MATLAB • MATLAB is relatively easy to learn • MATLAB code is optimized to be relatively quick when performing matrix operations • MATLAB may behave like a calculator or as a programming language • MATLAB is interpreted, errors are easier to fix • Although primarily procedural, MATLAB does have some object-oriented elements
Weaknesses of MATLAB • MATLAB is not a General Purpose Programming Language • MATLAB is an interpreted language (making it for the most part slower than a compiled language such as C++) • MATLAB is designed for scientific computation and is not suitable for some things like parsing text.
APPLICATIONS OF MATLAB • Mathematical Calculations • Data Analysis & Visualization • Software Development • Simulation
Getting Started with MATLAB Command Window Current Directory and Workspace Command History Launch Pad
Basic Window • Command Window • Type commands • Workspace • view program variables • clear to clear • Double click on a variable to see it in the Array Editor • Command History • View past commands • Save a whole session using diary • Launch Pad • Access tools, Demos and Documentation
How to Open Matlab Editor • FILE • NEW • M-FILE / • Script • Other options are • Function • Class • Figure • Variable • Model • GUI • Etc Ctrl N
Basic Matlab Commands • MATLAB is case-sensitive. • clc: Clear command window. • clear: removes all variables from the workspace. • clear variables:does the same thing. • clear functions: Removes all compiled M- and MEX-functions. • clear all:Removes all variables, globals, functions and MEX links. • close all: closes all the figure windows • % : used for Comments • plot: Linear plot. • plot(X, Y): plot’s vector Y versus vector X. • ; : Semicolon at the end of a statement, suppresses output. • help : when used with command gives its syntax
Basic Arithmetic Operators + : Arithmetic addition - : Arithmetic subtraction * : Arithmetic multiplication / : Arithmetic division ^ : Exponent or power .* : Element by element multiplication ./ : Element by element Division .^ : Element by element Division
Operators (Relational, Logical) • == equal • ~= not equal • < less than • <= less than or equal • > greater than • >= greater than or equal 1. & AND 1. pi(π) = 3.14159265… 2. | OR 2. j = imaginary unit 3. ~ NOT 3.i = same as j
Built-in Waveform Functions • cos (): Generates a cosine wave • sin() : Generates a sine wave • square(): Generates a square wave • square( , duty): Generates a square with specified duty cycle • sawtooth(): Generates a sawtooth wave • sawtooth(t, 0.5): Generates a triangle wave
Sine-wave Generation clc; clear all; close all; frequency = 1000; timeperiod = 1/frequency; amplitude = 1; offset = 0; t = 0:0.00001: 2*timeperiod; out = offset + amplitude* sin(2*pi*frequency*t); plot(t, out);
How to Execute the code Method I Select all Right Click Evaluate Selection Method II Debug RUN Other Methods Press F5 Type File name in Command window and press “Enter”
Method II Debug RUN
Other Methods • Press F5 • Type File name in Command window and press “Enter” • Press Play Button
More commands • figure : Create figure window. • xlabel(‘ ’) : Allows you to label x-axis • ylabel(‘ ’) : Allows you to label x-axis • title(‘ ’) : Allows you to give title for plot • subplot( ) : Allows you to create multiple plots in the same window
Example xlabel(‘ Time ’) ylabel(‘ Amplitude ’) title(‘Generation of Sinusoidal Waveform ’)
B A C