Unformatted text preview:

1. IntroductionMATLAB is a high-level technical computing language and interactive environment for algorithm development, data visualization, data analysis, and numerical computation. Using MATLAB, you can solve technical computing problems faster than with traditional programming languages, such as C, C++, and Fortran.2. Field of MatlabMultivariable Calculus Ordinary Differential Equations Partial Differential Equations Computational Programming Numerical Analysis Computational Mechanics Control Systems Electromechanical Dynamics Flight Dynamics and Control Fluid Mechanics Digital Signal Processing Image Processing Speech Processing Fuzzy Controls Process Control Neurology Geology Oceanography Vibration Analysis Robotics Instrumentation and Measurement Physics Economics Soft Computing 3. Install Matlab1) Many PC at UTA already has Matlab.2) MatLab education version $99.3) Please do not use illegal software 4) Install Matlab and run.Exercise 1 Getting Start MatlabProgram DevelopmentThis section explains the basic steps in developing an M-file program in MATLAB. Associated with each step in this process are certain MATLAB tools and utilities that are fully documented in the Desktop Tools and Development Environment documentation.For more ideas on good programming style, see Program Development. The MATLAB Programming Tips is a compilation of useful pieces of information that can show you alternate and often more efficient ways to accomplish common programming tasks while also expanding your knowledge of MATLAB.Creating a ProgramYou can type in your program code using any text editor. This section focuses on using the MATLAB Editor/Debugger for this purpose. The Editor/Debugger is fully documented in Ways to Edit and Debug Files in the Desktop Tools and Development Environment documentation.The first step in creating a program is to open an editing window. To create a new M-file, type the word edit at the MATLAB command prompt. To edit an existing M-file, type edit followed by the filename:edit drawPlot.mMATLAB opens a new window for entering your program code. As you type in your program, MATLAB keeps track of the line numbers in the left column.Saving the ProgramIt is usually a good idea to save your program periodically while you are in the development process. To do this, click File -> Save in the Editor/Debugger. Enter a filename with a .m extension in the Save file as dialog box that appears and click OK. It is customary and less confusing if you give the M-file the same name as the first function in the M-file.Running the ProgramBefore trying to run your program, make sure that its M-file is on the MATLAB path. The MATLAB path defines those directories that you want MATLAB to know about when executing M-files. The path includes all the directories that contain functions provided with MATLAB. It should also include any directories that you use for your own functions.Use the which function to see if your program is on the path:which drawPlot D:\matlabR14\work\drawPlot.mIf not, add its directory to the path using the addpath function:addpath('D:\matlabR14\work')Now you can run the program just by typing the name of the M-file at the MATLAB command prompt:drawPlot(xdata, ydata)Basic Parts of an M-FileThis simple function shows the basic parts of an M-file. Note that any line that begins with % is notexecutable:function f = fact(n) Function definition line% Compute a factorial value. H1 line% FACT(N) returns the factorial of N, Help text% usually denoted by N!% Put simply, FACT(N) is PROD(1:N). Commentf = prod(1:n); Function bodyThe table below briefly describes each of these M-file parts. Both functions and scripts can have all of these parts, except for the function definition line which applies to functions only. These parts are described in greater detail following the table. M-File Element DescriptionFunction definition line(functions only)Defines the function name, and the number and order of input and output argumentsH1 line A one line summary description of the program, displayed when you request help on an entire directory, or when you use lookforHelp text A more detailed description of the program, displayed together with the H1 linewhen you request help on a specific functionFunction or scriptbodyProgram code that performs the actual computations and assigns values to any output argumentsComments Text in the body of the program that explains the internal workings of the programFunction Definition Line The function definition line informs MATLAB that the M-file contains a function, and specifies the argument calling sequence of the function. The function definition line for the fact function isAll MATLAB functions have a function definition line that follows this pattern.Function Name. Function names must begin with a letter, may contain any alphanumeric characters or underscores, and must be no longer than the maximum allowed length (returned bythe function namelengthmax). Because variables must obey similar rules, you can use the isvarname function to check whether a function name is valid:isvarname myfunAlthough function names can be of any length, MATLAB uses only the first N characters of the name (where N is the number returned by the function namelengthmax) and ignores the rest. Hence, it is important to make each function name unique in the first N characters:N = namelengthmaxN = 63Note Some operating systems may restrict file names to shorter lengths.The name of the text file that contains a MATLAB function consists of the function name with the extension .m appended. For example,average.mIf the filename and the function definition line name are different, the internal (function) name is ignored. Thus, if average.m is the file that defines a function named computeAverage, you would invoke the function by typingaverageNote While the function name specified on the function definition line does not have to be the same as the filename, it is best to use the same name for both to avoid confusion. Function Arguments. If the function has multiple output values, enclose the output argument list in square brackets. Input arguments, if present, are enclosed in parentheses following the function name. Use commas to separate multiple input or output arguments. Here is the declaration for a function named sphere that has three inputs and three outputs:function [x, y, z] =


View Full Document

UT Arlington CSE 1105 - MATLAB

Download MATLAB
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view MATLAB and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view MATLAB 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?