You are on page 1of 46

MATLAB

About MATLAB
MATLAB-MATrix LABoratory A numerical computing environment and programming language. Created by MathWorks Inc, MATLAB allows easy matrix manipulation, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages.

The beginning
MATLAB was invented in the late 1970s by Cleve Moler, then chairman of the Computer Science ,Department at the University of New Mexico In the mid to late 1970s, he was one of the authors of LINPACK and EISPACK, Fortran libraries for numerical computing.

He invented MATLAB, a numerical computing package, to give his students at the University of New Mexico easy access to these libraries without writing Fortran. In 1984, he co-founded The MathWorks with Jack Little to commercialize this program.

MATLAB contains toolboxes


Bioinformatics Toolbox Genetic Algorithm and Direct Search Toolbox Image Acquisition Toolbox Image Processing Toolbox Instrument Control Toolbox Mapping Toolbox Model-Based Calibration Toolbox Model Predictive Control Toolbox Neural Network Toolbox OPC Toolbox Optimization Toolbox Partial Differential Equation Toolbox RF Toolbox Signal Processing Toolbox Spline Toolbox Statistics Toolbox Symbolic Math Toolbox System Identification Toolbox Virtual Reality Toolbox Wavelet Toolbox

Communications Toolbox Control System Toolbox Curve Fitting Toolbox Data Acquisition Toolbox Database Toolbox Datafeed Toolbox Excel Link Filter Design Toolbox Filter Design HDL Coder Financial Toolbox Financial Derivatives Toolbox Fixed-Income Toolbox Fixed-Point Toolbox Fuzzy Logic Toolbox GARCH Toolbox

An extension of MATLAB
Simulink (Simulation and Link) is an extension of MATLAB by Mathworks Inc. It works with MATLAB to offer modeling, simulating, and analyzing of dynamical systems under a graphical user interface (GUI) environment. Simulink link contains toolboxes called blocksets

Event-Based Modeling Stateflow SimEvents Physical Modeling Simscape SimMechanics SimPowerSystems SimDriveline SimHydraulics Simulation Graphics Virtual Reality Toolbox Gauges Blockset

Blocksets

Control System Design and Analysis Simulink Control Design Simulink Response Optimization Simulink Parameter Estimation Aerospace Blockset Signal Processing and Communications Signal Processing Blockset Communications Blockset RF Blockset Video and Image Processing Blockset

Code Generation Real-Time Workshop Real-Time Workshop Embedded Coder Stateflow Coder Simulink HDL Coder Rapid Control Prototyping and HIL SW/HW xPC Target xPC Target Embedded Option Real-Time Windows Target Embedded Targets Target for Infineon C166 Target for Freescale MPC5xx Target for TI C2000 Target for TI C6000 Verification, Validation, and Testing Simulink Verification and Validation Simulink Design Verifier SystemTest MATLAB and Simulink Link Products Link for Analog Devices VisualDSP++ Link for Cadence Incisive Link for Code Composer Studio Link for ModelSim

Matrix operations
A=2; constant B=[ 1 2 3 ;4 5 6;7 8 9]; 3x3 matrix C= [ 2 4 6 8 9]; D= C+2; E= B (transpose) F= inv(B) inverse

Programming constructs
>> y=[]; >> for x=0.5:0.5:5 y=[y,2*x]; end >> y >> n=3; >> while(n ~= 0) n=n-1 end >> if(n < 0) -n elseif (n == 0) n=365 else n end

Files in matlab
*.m files both script and functions *.mat files Matlab data files in Simulink *.mdl

function y = average(x) % AVERAGE Mean of vector elements. % %AVERAGE(X), where X is a vector, is the mean of vector % elements. Nonvector input results in an error.% [m,n] = size(x); if (~((m == 1) | (n == 1)) | (m == 1 & n == 1)) error('Input must be a vector') end y = sum(x)/length(x); z = 1:99; average(z)

Script and mat


Sequence of commands- automated MAT file >> u = [1 3 -4]; >> v = [2 -1 7]; >> whos Name Size Bytes Class u 1x3 24 double array v 1x3 24 double array Grand total is 6 elements using 48 bytes >> save stuff.mat >> ls stuff.mat

Plots
x = 0:0.1:4; y = sin(x.^2).*exp(-x); stem(x,y)

x=0:0.05:5; y=sin(x.^2); plot(x,y);

Quiver field visualization


quiver(x,y,px,py,2,'k');

Plots and data visualization


2D and 3D graphics Volume visualization tools

Graphic User Interfaces in MATLAB The GUI contains


An axes component A pop-up menu listing three different data sets that correspond to MATLAB functions: peaks, membrane, and sinc A static text component to label the pop-up menu Three push buttons, each of which provides a different kind of plot: surface, mesh, and contour

Programming User Interface Controls


Check Box Edit Text List Box Pop-Up Menu Push Button Radio Button Slider Toggle Button

Skeletal template M-Code is generated automatically for the GUI Callback functions are available for user control

Callback functions
ButtonDownFcn Executes when the user presses a mouse button while the pointer is on or within five pixels of a component or figure. Callback Control action. Executes, for example, when a user clicks a push button or selects a menu item.

function pushbutton1_Callback(hObject,eventdata) display Goodbye close(gcbf)

Graphics handler for GUI


Handler manipulate graphic properties of GUI

Dynamic Link Libraries-Access functions stored in external shared library (.dll) files Java--Work with objects constructed from Java API and third-party class packages Component Object Model and ActiveX--Integrate COM components into your application Web Services--Communicate between applications over a network using SOAP and WSDL Serial Port Devices- communicate with ports for external data transfer

External Interfaces

Commonly used Toolboxes


Control System Toolbox Signal Processing Toolbox Statistics Toolbox Optimization Toolbox Image Processing Toolbox Instrument control Toolbox

Control system toolbox


Open-loop step response num=1; den=[1 10 20]; plant=tf(num,den); step(plant)

num = 50; den = [1 9 30 40]; sys = tf(num,den); bode(sys)

h = tf([2 5 1],[1 2 3]); rlocus(h)

SISOtool

Simulink

Simulink *.mdl

Simulation configuration

Symbolic math toolbox


syms x f = sin(5*x) diff(f) Ans=5*cos(5*x) Syms a,b,c,x F=a*x^2+b*x+c Solve(F) Ans= ( -b+(b^2-4*a*c)1/2 )/2*a

Image processing toolbox


[X1,map1]=imread('forest.tif'); [X2,map2]=imread('trees.tif'); subplot(1,2,1), subimage(X1,map1) subplot(1,2,2), subimage(X2,map2)

Partial Differential Equation Toolbox

Signal processing- FDAtool

User community (MATLAB Central)

LINKEXCHANGE-Links to latest development FILEEXCHANGE-The MATLAB Central File Exchange contains thousands of files contributed by users and developers of MATLAB, Simulink and related products NEWSGROUP-Queries ,FAQ and Webinars

Some Tutorial links


http://www.mathworks.com/academia/student_c enter/tutorials/launchpad.html http://www.ee.ucr.edu/EESystems/docs/Matlab/# calculus http://www.library.cmu.edu/ctms/ctms/index.htm http://www.duke.edu/~hpgavin/matlab.html http://www.mathworks.com/company/newsletters /news_notes/clevescorner/dec04.html http://www.mathworks.com/access/helpdesk/hel p/helpdesk.html

You might also like