Anda di halaman 1dari 12

1 INTRODUCTION TO MATLAB 1.1.1What Is MATLAB? MATLAB is a high-performance language for technical computing.

It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include Math and computation Algorithm development Data acquisition Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, in cluding graphical user interface building. MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar non interactive language such as C or FORTRAN. The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the state of the art in software for matrix computation. MATLAB has evolved over a period of years with input from many users. In university environments, it is the standard instructional tool for introductory and advanced courses in mathematics, engineering, and science. In industry, MATLAB is the tool of choice for highproductivity research, development, and analysis.

MATLAB features a family of add-on application-specific solutions called toolboxes. Very important to most users of MATLAB, toolboxes allow you to learn and apply specialized technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are available include signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many others. 1.1.2 The MATLAB System: The MATLAB system consists of five main parts: i) Development Environment: This is the set of tools and facilities that help you use MATLAB functions and files. Many of these tools are graphical user interfaces. It includes the MATLAB desktop and Command Window, a command history, an editor and debugger, and browsers for viewing help, the workspace, files, and the search path.

ii) The MATLAB Mathematical Function: This is a vast collection of computational algorithms ranging from elementary functions like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse, matrix Eigen values, Bessel functions, and fast Fourier transforms. iii) The MATLAB Language: This is a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. It allows both "programming in the small" to rapidly create quick and dirty throw-away programs, and "programming in the large" to create complete large and complex application programs.

iv) Graphics: MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. It includes high-level functions for two-dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. It also includes low-level functions that allow you to fully customize the appearance of graphics as well as to build complete graphical user interfaces on your MATLAB applications. v) The MATLAB Application Program Interface (API): This is a library that allows you to write C and Fortran programs that interact with MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and for reading and writing MAT-files.

MATLAB WORKING ENVIRONMENT: 1.1.3 MATLAB DESKTOP: Matlab Desktop is the main Matlab application window. The desktop contains five sub windows, the command window, the workspace browser, the current directory window, the command history window, and one or more figure windows, which are shown only when the user displays a graphic. The command window is where the user types MATLAB commands and expressions at the prompt (>>) and where the output of those commands is displayed. MATLAB defines the workspace as the set of variables that the user creates in a work session. The workspace browser shows these variables and some information about them. Double clicking on a variable in the workspace browser launches the Array Editor, which can be used to obtain information and income instances edit certain properties of the variable. The current Directory tab above the workspace tab shows the contents of the current

directory, whose path is shown in the current directory window. For example, in the windows

operating system the path might be as follows: C:\MATLAB\Work, indicating that directory work is a subdirectory of the main directory MATLAB; WHICH IS INSTALLED IN DRIVE C. clicking on the arrow in the current directory window shows a list of recently used paths. Clicking on the button to the right of the window allows the user to change the current directory. MATLAB uses a search path to find M-files and other MATLAB related files, which are organize in directories in the computer file system. Any file run in MATLAB must reside in the current directory or in a directory that is on search path. By default, the files supplied with MATLAB and math works toolboxes are included in the search path. The easiest way to see which directories are on the search path. The easiest way to see which directories are soon the search paths, or to add or modify a search path, is to select set path from the File menu the desktop, and then use the set path dialog box. It is good practice to add any commonly used directories to the search path to avoid repeatedly having the change the current directory. The Command History Window contains a record of the commands a user has entered in the command window, including both current and previous MATLAB sessions. Previously entered MATLAB commands can be selected and re-executed from the command history window by right clicking on a command or sequence of commands. This action launches a menu from which to select various options in addition to executing the commands. This is useful to select various options in addition to executing the commands. This is a useful feature when experimenting with various commands in a work session. 1.1.4 Using the MATLAB Editor to create M-Files: The MATLAB editor is both a text editor specialized for creating M-files and a graphical MATLAB debugger. The editor can appear in a window by itself, or it can be a sub window in the desktop. M-files are denoted by the extension .m, as in pixelup.m. The MATLAB editor window has numerous pull-down menus for tasks such as saving, viewing, and debugging files. Because it performs some simple checks and also uses color to differentiate between various elements of code, this text editor is recommended as the tool of choice for writing and editing Mfunctions. To open the editor , type edit at the prompt opens the M-file filename.m in an editor

window, ready for editing. As noted earlier, the file must be in the current directory, or in a directory in the search path. 1.1.5 Getting Help: The principal way to get help online is to use the MATLAB help browser, opened as a separate window either by clicking on the question mark symbol (?) on the desktop toolbar, or by typing help browser at the prompt in the command window. The help Browser is a web browser integrated into the MATLAB desktop that displays a Hypertext Markup Language (HTML) documents. The Help Browser consists of two panes, the help navigator pane, used to find information, and the display pane, used to view the information. Self-explanatory tabs other than navigator pane are used to perform a search. 1.1.6 Digital Image Processing in MATLAB: Digital Image Processing (DIP) is the area characterized by the need for extensive experimental work to establish the viability of proposed solutions to a given problem. An important characteristic underlying the design of image processing systems is the significant level of testing and experimentation that is normally required. This characteristic implies that the ability to formulate approaches and quickly prototype candidate solutions generally plays a major role in reducing the cost and time required to arrive at a viable system implementation. The software code and supporting tools used for DIP are based on leading software in the field: MATLAB and the Image Processing Toolbox from The Math Works, Inc. Image Processing Toolbox provides a comprehensive set of reference-standard algorithms and graphical tools for image processing, analysis, visualization, and algorithm development. You can perform image enhancement, image deblurring, feature detection, noise reduction, image segmentation, spatial transformations, and image registration. Many functions in the toolbox are multithreaded to take advantage of multi core and multiprocessor computers. Image Processing Toolbox supports a diverse set of image types, including high dynamic range, giga pixel resolution, ICC-compliant color, and tomo graphic images. Graphical tools let you explore an image, examine a region of pixels, adjust the contrast, create contours or histograms,

and manipulate regions of interest (ROIs). With the toolbox algorithms you can restore degraded images, detect and measure features, analyze shapes and textures, and adjust the color balance of images. Key Features: Image enhancement, filtering, and deblurring Image analysis, including segmentation, morphology, feature extraction, and

measurement Spatial transformations and image registration Image transforms, including FFT, DCT, Radon, and fan-beam projection Workflows for processing, displaying, and navigating arbitrarily large images Modular interactive tools, including ROI selections, histograms, and distance measurements ICC color management Multidimensional image processing Image-sequence and video display DICOM import and export

4.1 How to start and quit MATLAB? PC - a double click on the Matlab icon, UNIX system - setup Matlab (return). Matlab on both system leave a Matlab session by typing: Quit or by typing Exit at the Matlab prompt. .

4.3 Matrix, Vector & Scalar Three fundamental concepts in MATLAB, and in linear algebra, are scalars, vectors and matrices. A scalar is simply just a fancy word for a number (a single value). A vector is an ordered list of numbers (one-dimensional). In MATLAB they can be represented as a row-vector or a column-vector.

A matrix is a rectangular array of numbers (multi-dimensional). In MATLAB, a twodimensional matrix is defined by its number of rows and columns. Matlab uses variables that are defined to be matrices. A matrix is a collection of numerical values that are organized into a specific configuration of rows and columns. The number of rows and columns can be any number. A= [1 2 3 4 5 6 7 8]; A is for example, 2 rows and 4 columns define a 2 x 4 matrix which has 8 elements in total. A scalar is represented by a 1 x 1 matrix in Matlab: a=1. A vector of n elements can be represented by a n x 1 matrix, in which case it is called a column vector, or a vector can be represented by a 1 x n matrix, in which case it is called a row vector of n elements. x = [3.5, 33.22, 24.5]; x1 = [2 5 3 - 1]; The matrix name can be any group of letters and numbers up to 19, but always beginning with a letter. Matlab is "case sensitive", that is, it treats the name 'C' and 'c' as two different variables. Similarly, 'MID' and 'Mid' are treated as two different variables. x is a row vector or 1 x 3 matrix x1 is column vector or 4 x 1 matrix

4.4 Some basic commands S.no 1 2 3 4 5 6 7 8 9 Command pwd demo who whos clear clear x close figure hold on Description prints working directory demonstrates what is possible in Matlab lists all of the variables in your Matlab workspace list the variables and describes their matrix size erases variables and functions from memory erases the matrix 'x' from your workspace by itself, closes the current figure window creates an empty figure window holds the current plot and all axis properties so that subsequent graphing commands add to the existing graph 10 hold off sets the next plot property of the current axes to "replace"

11

find

find indices of nonzero elements e.g.: d = find(x>100) returns the indices of the vector x that are greater than 100

12 13

break for

terminate execution of m-file or WHILE or FOR loop repeat statements a specific number of times, the general form of a FOR statement is: END a. for n=1:cc/c; FOR variable = expr, statement, ..., statement

b. magn(n,1)=NaNmean(a((n-1)*c+1:n*c,1)); c. end

14

diff

difference and approximate derivative e.g.: DIFF(X) for a vector X, is [X(2)-X(1) X(3)-X(2) ... X(n)-X(n-1)].

15

NaN

the arithmetic representation for Not-a-Number, a NaN is obtained as a result of mathematically undefined operations like 0.0/0.0

16

INF

the arithmetic representation for positive infinity, a infinity is also produced by operations like dividing by zero, e.g. 1.0/0.0, or from overflow, e.g. exp(1000).

17

save

saves all the matrices defined in the current session into the file, matlab.mat, located in the current working directory

18 19

load

loads contents of matlab.mat into current workspace

save filename x y saves the matrices x, y and z into the file titled filename.mat z

20

save filename x y save the matrices x, y and z into the file titled filename.dat z /ascii

21

load filename

loads the contents of filename into current workspace; the file can be a binary (.mat) file

22 23 24

load filename.dat xlabel( ) ylabel( )

loads the contents of filename.dat into the variable filename Allows you to label x-axis Allows you to label y-axis

25 26

title( ) subplot()

Allows you to give title for plot Allows you to create multiple plots in the same window.

4.5 Some kind of plot commands Different kinds of plots are.... S.no 1 2 Commands plot(x,y) plot(y) Description creates a Cartesian plot of the vectors x & y creates a plot of y vs. the numerical values of the elements in the y-vector 3 4 5 6 semilogx(x,y) semilogy(x,y) loglog(x,y) polar(theta,r) plots log(x) vs. y plots x vs. log(y) plots log(x) vs. log(y) creates a polar plot of the vectors r & theta where theta is in radians 7 bar(x) creates a bar graph of the vector x. (Note also the command stairs(x)) 8 bar(x,y) creates a bar-graph of the elements of the vector y, locating the bars according to the vector elements of 'x' 9 10 11 Grid title('text') xlabel('text') creates a grid on the graphics plot places a title at top of graphics plot writes 'text' beneath the x-axis of a plot

12 13 14

ylabel('text') text(x,y,'text') text(x,y,'text','sc')

writes 'text' beside the y-axis of a plot writes 'text' at the location (x,y) writes 'text' at point x,y assuming lower left corner is (0,0) and upper right corner is (1,1)

15

axis([xmin ymax])

xmax

ymin sets scaling for the x- and y-axes on the current plot

4.6 ALGEBRAIC OPERATIONS IN MATLAB Scalar Calculations are... + * / \ ^ Addition Subtraction Multiplication Right division (a/b means a b) left division (a\b means b a) Exponentiation 3*4 4/5 executed in 'matlab' gives ans=12 gives ans=0.8

For example

Array products: Recall that addition and subtraction of matrices involved addition or subtraction of the individual elements of the matrices. Sometimes it is desired to simply

multiply or divide each element of an matrix by the corresponding element of another matrix 'array operations.

Array or element-by-element operations are executed when the operator is preceded by a '.' (Period): a .* b multiplies each element of a by the respective element of b a ./ b divides each element of a by the respective element of b a .\ b divides each element of b by the respective element of a a .^ b raise each element of a by the respective b element

Anda mungkin juga menyukai