INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD. July 2018
|
|
- Lambert Jackson
- 5 years ago
- Views:
Transcription
1 INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths July 2018
2 Outline MATLAB Scripts Relational Operations Program Control Statements Writing MATLAB Functions and Scripts
3 Matlab Scripts and Functions A sequence of matlab commands can be put into a file which can later be executed by invoking its name. The files which have.m extensions are recognised by Matlab as Matlab Script or Matlab Function files. If an m file contains the keyword function at the beginning of its first line it is treated as a Matlab function file. Functions make up the core of Matlab. Most of the Matlab commands apart from a few built-in ones are in fact matlab functions.
4 Accessing the Matlab Functions and Scripts Most Matlab commands are in fact functions (provided in.m files of the same name) residing in one of the Matlab path directories. See path command. Matlab searches for scripts and files in the current directory first and then in the Matlab path going from left to right. If more than one function/script exists with the same name, the first one to be found is used. name-clash To avoid inadvertent name-clash problems use the which command to check if a function/script exists with a name before using that name as the name of your own function/script or to find out that the function you are using is really the one you intended to use! Example : which mysolver lookfor and what commands can also help locate Matlab functions. Having located a function use the type command to list its contents.
5 Relational & Logical Operations RELATIONAL OPERATIONS Comparing scalars, vectors or matrices. < less than <= less than or equal to > greater than >= greater than or equal to = = equal to ~ = not equal to Result is a scalar, vector or matrix of of same size and shape whose each element contain only 1 ( to imply TRUE) or 0 (to imply FALSE ).
6 Relational Operations continued. Example 1: A = magic(6) ; A is 6x6 matrix of magic numbers. P = ( rem( A,3) = = 0 ) ; Elements of P divisible by 3 are set to 1 while others will be 0. Example 2: Find all elements of an array which are greater than 0.7 and set them to 0.5. A = rand(12,1) ; ---> a vector of random no.s A( A >= 0.7 )=0.5; ----> only the elements of A which are >=0.7 will be set to 0.5. Example 3: given a vector of numbers b, eliminate all elements of that vector whose values lie outside the range 0.0 to b= ( rand(30,1) -0.1) *120 b( b < 0.0 b > ) = []
7 Logical Operations These are : & (meaning AND) (meaning OR) ~ (meaning NOT) Operands are treated as if they contain logical variables by assuming that 0=FALSE NON-ZERO=TRUE Example : If a = [ ] ; b = [ ] ; c=a&b will result in c = [ ] d=a b will result in d= [ ] e=~a will result in e= [ ] There is one other function to complement these operations which is xor meaning Exclusive-OR. Therefore; f = xor( a, b ) will return f= [ ] ( Note: any non-zero value is treated as 1 when logical operation is applied)
8 Exercises involving Logical Operations & Find function Type in the following lines to investigate logical operations and also use of the find function when accessing arrays via an indices vector. A = magic(4) A>7 ind = find (A>7) A(ind) A(ind)= 0
9 Summary of Program Control Statements Conditional control if, else, elseif statements switch statement Loop control for loops while loops break statement continue statement Error Control try catch end return statement
10 if statements if logical_expression statement(s) end or if logical_expression statement(s) else statement(s) end or...
11 if statements continued... if logical_expression statement(s) elseif logical_expression statement(s) else statement(s) end
12 if statement examples if a < 0.0 disp( 'Negative numbers not allowed '); disp(' setting the value to 0.0 ' ); a = 0.0 ; elseif a > disp(' Number too large' ) ; disp(' setting the value to ' ); a = 100; end NOTES: In the above example if a was an array or matrix then the condition will be satisfied if and only if all elements evaluated to TRUE
13 Conditional Control Logical operations can be freely used in conditional statements. Example: if (attendance >= 0.90) & (grade_average >= 50) passed = 1; else failed = 1; end; To check the existence of a variable use function exist. if ~exist( scalevar ) scalevar = 3 end
14 for loops this is the looping control (similar to repeat, do or for constructs in other programming languages): SYNTAX: for v = expression statement(s) end where expression is an array or matrix. If it is an array expression then each element is assigned one by one to v and loop repeated. If matrix expression then each column is assigned to v and the loop repeated. for loops can be nested within each other
15 for loops continued... EXAMPLES: sum = 0.0 for v = 1:5 sum = sum + 1.0/v end below example evaluates the loop with v set to 1,3,5,, 11 for v = 1:2:11 statement(s) end
16 for loops examples Loop counter is a scalar w = [ ] % here a will take values 1,5,2 so on.. for a = w statement(s) end Loop counter is a vector A= rand( 4,10) % A is 4 rows and 10 columns. % The for loop below will be executed 10 times ( once for each column) and during each iteration v will be a column vector of length 4 rows. for v = A statement(s) end
17 while loops while loops repeat a group of statements under the control of a logical condition. SYNTAX: while expression end : statement(s) :
18 while loops continued.. Example: n = 1 while prod(1:n) < 1E100 end n= n + 1 The expression controlling the while loop can be an array or even a matrix expression in which case the while loop is repeated until all the elements of the array or matrix becomes zero.
19 Differences between scripts and functions Matlab functions do not use or overwrite any of the variables in the workspace as they work on their own private workspace. Any variable created within a function is not available when exited from that function. ( Exception to this rule are the Global and Persistent variables)
20 Scripts vs Functions Script Works in Matlab Workspace ( all variables available) Any variable created in a script remains available upon exit As Matlab workspace is shared communication is possible via the values of variables in the workspace. Any alteration to values of variables in a script remains in effect even after returning from that script. Function Works in own workspace (only the variables passed as arguments to functions are available ) ( exception: global ) Any variable created in a function is destroyed upon exit exception: persistent Only communications is via parameters passed to functions and value(s) returned via the output variables of functions. Parameters are passes by reference but any alterations made to these parameters in the called function initiates creation of a copy. This ensures that input parameters remain unaltered in the calling function.
21 The function-definition line General Format: function return_vars = name ( input_args ) Matlab functions can return no value or many values, each of the values being scalars or general matrices. If a function returns no value the format is; function name ( input_args) If the function returns multiple values the format is; function [a,b,c ] = name ( input_args ) If the function name and the filename where the function resides are not the same the filename overrides the function name.
22 The H1 ( heading line) of function files Following the function definition line, the next line, if it is a comment is called the H1 line and is treated specially. Matlab assumes it to be built-in help on the usage of that function. Comment lines immediately following the H1 comment line are also treated to be part of this built-in help ( until a blank line or an executable statement is encountered) help function-name command prints out these comment lines, but the lookfor command works only on the first (H1) comment line.
23 About Functions Function files can be used to extend Matlab s features. As a matter of fact most of the Matlab commands and many of the toolboxes are essentially collections of function files. When Matlab encounters a token i.e a name in the command line it performs the following checks until it resolves the action to take; Check if - it is a variable it is an anonymous function it is a nested function it is a sub-function ( local function ) it is a private function if it is a p-code or.m file in the Matlab s search path When a function is called it gets parsed into Pseudo-Code and stored into Matlab s memory to save parsing it the next time. Pre-parsed versions of the functions can be saved as Pseudo-Code (.p) files by using the pcode command. Example : pcode myfunc
24 Variables in Functions Function returns values (or alters values) only via their output parameters or via the global statement. Functions can not alter the value of its input arguments in the calling routine. For efficiency reasons, where possible, input parameters are passed via the address and not via value but care is taken not to alter the value of input parameters in the calling routine Variables created within the function are local to the function alone and not part of the MATLAB workspace ( they reside in their own function-workspace) Such local variables cease to exist once the function is exited, unless they have been declared in a global statement or are declared as persistent. Global variables: Global statement can be used in a function.m file to make variables from the base workspace available. This is equivalent to /common/ features of Fortran and persistent features of C. Global statement can be used in multiple functions as well as in top level ( to make it available to the workspace )
25 An example function file. function xm = mean(x) % MEAN : Calculate the mean value. % For vectors: returns mean-value. % For matrices: returns the mean value of % each column. [ m, n ] = size ( x ); if m = = 1 m = n ; end xm = sum(x)/m;
26 Practice Session 1 Writing Matlab Functions Perform the first exercise in the exercises_programming file to write a function that calculates the value of sin().
27 Function Arguments Functions can have variable numbers of input and output arguments. As well as each argument being a multi-dimensional array. Size of the input argument arrays can be found by the use of the size function. The actual numbers of input arguments when the function was called can be found by using the nargin function Similarly the actual number of output arguments expected at the time of the call can be deduced by using the nargout function.
28 Example uses of nargin nargout Number of parameters supplied to a function during a call can be discovered using the nargin() function. Similarly number of arguments expected to be returned during a call can be discovered using the nargout() function. For example if a function is referenced as: [ x, y ] = myfun ( a, b, c, d ) Then in myfun nargin should return 4 and nargout should return 2 Referencing the same function as: z = myfun( e, f ) would result is nargin returning 2 and nargout returning 1.
29 Exercises 2 In the programming directory you will find a MATLAB function named mystat1.m. Using that function tackle Exercises 2 from the exercises_programming sheet.
30 Types of Functions There are a number of types of functions which differ from each other mainly due to the visibility aspect. Following slides list these function types.
31 Anonymous Functions These are functions created during a session on the fly and not saved into a file. They remain in the memory until cleared Example: cube x.^3 ; a = cube(3)
32 Local Functions A function m-file can contain a list of functions. The first one to appear is the primary function (which should have the same name as the m-filename ). The subsequent functions are called the local functions and are only visible to the primary function and the other local functions in the same m-file.
33 Local Functions: Example function [avg,med] = newstats(u) % Primary function % NEWSTATS Find mean and median with internal functions. n = length(u); avg = mean(u,n); med = median(u,n); function a = mean(v,n) % Calculate average. a = sum(v)/n; function m = median(v,n) % Calculate median. w = sort(v); if rem(n,2) == 1 m = w((n+1)/2); else m = (w(n/2)+w(n/2+1))/2; end % Subfunction % Subfunction
34 Nested Functions A nested function is a function that is completely contained within another function. They can access all the variables of the containing function Example: function [avg,med] = newstat2(u) % This is the primary function % NEWSTAT2 Finds mean and median of a vector using nested functions. n = length(u); avg = mean; med = median; function a = mean % Nested Function % Calculate average. a = sum(u)/n; end function m = median % Nested Function % Calculate median. w = sort(u); if rem(n,2) == 1 m = w((n+1)/2); else m = (w(n/2)+w(n/2+1))/2; end end end
35 Private Functions Private functions are functions that reside in subdirectories with the special name private. They are visible only to the functions in the parent directory. This feature can be used to over-ride the global functions with your own versions only for certain tasks. This is because Matlab looks into private directory first (if exists) for any function references.
36 Function Handles The main use of function handles is to provide the ability to apply the same process to different functions. Example: Matlab function integral can be invoked as; integral ( function_handle, lower_limit, upper_limit ) For example: integral (@sin, 0.0, 2.0 ) integral -1.0, 2.0 )
37 Example of a function handle Create a function file myfun.m which contains the following lines and save it. function y = myfun ( x ) end y = x.*2 - sin( x ).*2 ; You can now find the integral of this function easily by using the integral function. For example: s = integral 1, 10 )
38 Practice Session 3 In the programming directory you will find a function named findrt1.m. Using that function perform exercises 3 from the exercises_programming sheet.
39 break statement Breaks out of the while and for loop control structures. Note that there are no go to or jump statements in Matlab ( goto_less programming ) continue statement This statement passes control to the next iteration of the for or while loop in which it appears, skipping any remaining statements in the body of the loop.
40 break statement example This loop will repeat until a suitable value of b is entered. a=5; c=3; while 1 b = input ( Enter a value for b: ); if b*b < 4*a*c disp ( There are no real roots ); break end end
41 switch statement Execute only one block from a selection of blocks of code according to the value of a controlling expression. Example: method = 'Bilinear'; % note: lower converts string to lower-case. switch lower(method) case {'linear','bilinear'} disp('method is linear') case 'cubic' disp('method is cubic') case 'nearest' disp('method is nearest') otherwise disp('unknown method.') end Note: only the first matching case executes, i.e. control does not drop through.
42 return statement This statement terminates the current sequence of commands and returns the control to the calling function (or keyboard it was called from top level) There is no need for a return statement at the end of a function although it is perfectly legal to use one. When the programcontrol reaches the end of a function the control is automatically passed to the calling program. return may be inserted anywhere in a function or script to cause an early exit from it.
43 try catch construct This is Matlab s version of error trapping mechanism. Syntax: try, statement, catch, statement, end When an error occurs within the try-catch block the control transfers to the catch-end block. The function lasterr can than be invoked to see what the error was.
44 Handling text There are two ways of storing text in MATLAB. 1. Character arrays 2. Character strings Character arrays : This is the traditional method of storing text. They can be entered into Matlab by surrounding them within single quotes. Example: height= h ; s = my title ; Each character is stored into a single two-byte element. The string is treated as an array. Therefore can be accessed manipulated by using array syntax. For example: s(4:8) will return title. Various ways of conversion to/from character arrays to numeric data is possible; Examples: title= my title ; double(title) > will display : grav = 9.81; gtitle1 = num2str(grav) > will create string gtitle1= 9.81 gtitle2 = sprintf( %f, grav) > will create string gtitle2= A= [65:75] ; char(a) > will display ABCDEFGHIJK. Now try : A= A+8 ; char(a) What do you see? Character strings have recently (2016) been introduced. A character string is stored by entering the string in double quotes. Example: anote = The defining equation ;
45 Keyboard User Interactions Prompting for input and reading it can be achieved by the use of the input function: Example: n = input ( Enter a number: ); will prompt for a number and read it into the variable named n.
46 Other useful commands to control or monitor execution echo > display each line of command as it executes. echo on or echo off keyboard > take keyboard control while executing a Matlab Script. pause > pause execution until a key presses or a number of seconds passed. pause or pause (n) for n-seconds pause
47 END
Introduction to Matlab
Introduction to Matlab Deniz Savas and Mike Griffiths Corporate Information and Computing Services The University of Sheffield, U.K. d.savas@sheffield.ac.uk m.griffiths@sheffield.ac.uk Part 1 - Contents
More informationLab of COMP 406 Introduction of Matlab (III) Programming and Scripts
Lab of COMP 406 Introduction of Matlab (III) Programming and Scripts Teaching Assistant: Pei-Yuan Zhou Contact: cspyzhou@comp.polyu.edu.hk Lab 3: 26 Sep., 2014 1 Open Matlab 2012a Find the Matlab under
More informationSECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB
SECTION 2: PROGRAMMING WITH MATLAB MAE 4020/5020 Numerical Methods with MATLAB 2 Functions and M Files M Files 3 Script file so called due to.m filename extension Contains a series of MATLAB commands The
More informationIntroduction to MATLAB
Introduction to MATLAB 1 Introduction to MATLAB A Tutorial for the Course Computational Intelligence http://www.igi.tugraz.at/lehre/ci Stefan Häusler Institute for Theoretical Computer Science Inffeldgasse
More informationMini-Matlab Lesson 5: Functions and Loops
Mini-Matlab Lesson 5: Functions and Loops Writing Functions and Scripts Contents Relational and logical operators IF loops FOR loops WHILE loops Scripts and functions Defining and using functions Anonymous
More informationProgramming in MATLAB
Programming in MATLAB Scripts, functions, and control structures Some code examples from: Introduction to Numerical Methods and MATLAB Programming for Engineers by Young & Mohlenkamp Script Collection
More informationfunction [s p] = sumprod (f, g)
Outline of the Lecture Introduction to M-function programming Matlab Programming Example Relational operators Logical Operators Matlab Flow control structures Introduction to M-function programming M-files:
More information7 Control Structures, Logical Statements
7 Control Structures, Logical Statements 7.1 Logical Statements 1. Logical (true or false) statements comparing scalars or matrices can be evaluated in MATLAB. Two matrices of the same size may be compared,
More informationEL2310 Scientific Programming
Lecture 4: Programming in Matlab Yasemin Bekiroglu (yaseminb@kth.se) Florian Pokorny(fpokorny@kth.se) Overview Overview Lecture 4: Programming in Matlab Wrap Up More on Scripts and Functions Wrap Up Last
More informationIntroduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices
Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are
More informationEL2310 Scientific Programming
(pronobis@kth.se) Overview Overview Wrap Up More on Scripts and Functions Basic Programming Lecture 2 Lecture 3 Lecture 4 Wrap Up Last time Loading data from file: load( filename ) Graphical input and
More informationMATLAB Second Seminar
MATLAB Second Seminar Previous lesson Last lesson We learnt how to: Interact with MATLAB in the MATLAB command window by typing commands at the command prompt. Define and use variables. Plot graphs It
More informationComputational Methods of Scientific Programming
12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring, Jim Elliot, Chris Hill, Summary of Today s class We will look at Matlab: History Getting help Variable definitions and
More informationMATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)
Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal
More informationFUNCTIONS ( WEEK 5 ) DR. USMAN ULLAH SHEIKH DR. MUSA MOHD MOKJI DR. MICHAEL TAN LONG PENG DR. AMIRJAN NAWABJAN DR. MOHD ADIB SARIJARI
FUNCTIONS SKEE1022 SCIENTIFIC PROGRAMMING ( WEEK 5 ) DR. USMAN ULLAH SHEIKH DR. MUSA MOHD MOKJI DR. MICHAEL TAN LONG PENG DR. AMIRJAN NAWABJAN DR. MOHD ADIB SARIJARI OBJECTIVES Create Function 1) Create
More informationIntroduction to Matlab. By: Hossein Hamooni Fall 2014
Introduction to Matlab By: Hossein Hamooni Fall 2014 Why Matlab? Data analytics task Large data processing Multi-platform, Multi Format data importing Graphing Modeling Lots of built-in functions for rapid
More informationLecturer: Keyvan Dehmamy
MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications
More informationProgramming 1. Script files. help cd Example:
Programming Until now we worked with Matlab interactively, executing simple statements line by line, often reentering the same sequences of commands. Alternatively, we can store the Matlab input commands
More informationIntroduction. Like other programming languages, MATLAB has means for modifying the flow of a program
Flow control 1 Introduction Like other programming languages, MATLAB has means for modying the flow of a program All common constructs are implemented in MATLAB: for while then else switch try 2 FOR loops.
More informationIntroduction to Matlab
Introduction to Matlab Weichung Wang 2003 NCTS-NSF Workshop on Differential Equations, Surface Theory, and Mathematical Visualization NCTS, Hsinchu, February 13, 2003 DE, ST, MV Workshop Matlab 1 Main
More informationAN INTRODUCTION TO MATLAB
AN INTRODUCTION TO MATLAB 1 Introduction MATLAB is a powerful mathematical tool used for a number of engineering applications such as communication engineering, digital signal processing, control engineering,
More informationIntroduction to Matlab
Introduction to Matlab Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control Using of M-File Writing User
More informationProgramming for Experimental Research. Flow Control
Programming for Experimental Research Flow Control FLOW CONTROL In a simple program, the commands are executed one after the other in the order they are typed. Many situations require more sophisticated
More informationChapters 6-7. User-Defined Functions
Chapters 6-7 User-Defined Functions User-Defined Functions, Iteration, and Debugging Strategies Learning objectives: 1. Write simple program modules to implement single numerical methods and algorithms
More informationChapter 3: Programming with MATLAB
Chapter 3: Programming with MATLAB Choi Hae Jin Chapter Objectives q Learning how to create well-documented M-files in the edit window and invoke them from the command window. q Understanding how script
More informationUser Defined Functions
User Defined Functions 120 90 1 0.8 60 Chapter 6 150 0.6 0.4 30 0.2 180 0 210 330 240 270 300 Objectives Create and use MATLAB functions with both single and multiple inputs and outputs Learn how to store
More informationRepetition Structures Chapter 9
Sum of the terms Repetition Structures Chapter 9 1 Value of the Alternating Harmonic Series 0.9 0.8 0.7 0.6 0.5 10 0 10 1 10 2 10 3 Number of terms Objectives After studying this chapter you should be
More informationMore on Functions. Dmitry Adamskiy 07 Dec 2011
More on Functions Dmitry Adamskiy dmitry@cs.rhul.ac.uk 07 Dec 2011 1 Other Types of Functions Subfunctions Anonymous functions Inline functions 2 Subfunctions We can place additional functions within the
More informationGetting To Know Matlab
Getting To Know Matlab The following worksheets will introduce Matlab to the new user. Please, be sure you really know each step of the lab you performed, even if you are asking a friend who has a better
More informationENGR 1181 MATLAB 09: For Loops 2
ENGR 1181 MATLAB 09: For Loops Learning Objectives 1. Use more complex ways of setting the loop index. Construct nested loops in the following situations: a. For use with two dimensional arrays b. For
More informationGetting started with MATLAB
Sapienza University of Rome Department of economics and law Advanced Monetary Theory and Policy EPOS 2013/14 Getting started with MATLAB Giovanni Di Bartolomeo giovanni.dibartolomeo@uniroma1.it Outline
More informationUniversity of Alberta
A Brief Introduction to MATLAB University of Alberta M.G. Lipsett 2008 MATLAB is an interactive program for numerical computation and data visualization, used extensively by engineers for analysis of systems.
More informationIntroduction to Matlab
Introduction to Matlab 1 Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control Using of M-File Writing User
More informationC/C++ Programming for Engineers: Matlab Branches and Loops
C/C++ Programming for Engineers: Matlab Branches and Loops John T. Bell Department of Computer Science University of Illinois, Chicago Review What is the difference between a script and a function in Matlab?
More informationIntroduction to Octave/Matlab. Deployment of Telecommunication Infrastructures
Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,
More informationIntroduction to MATLAB
Chapter 1 Introduction to MATLAB 1.1 Software Philosophy Matrix-based numeric computation MATrix LABoratory built-in support for standard matrix and vector operations High-level programming language Programming
More informationChapter 7: Programming in MATLAB
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Computer Programming (ECIV 2302) Chapter 7: Programming in MATLAB 1 7.1 Relational and Logical Operators == Equal to ~=
More informationECE 102 Engineering Computation
ECE 102 Engineering Computation Phillip Wong MATLAB Function Files Nested Functions Subfunctions Inline Functions Anonymous Functions Function Files A basic function file contains one or more function
More informationMatlab Primer. Lecture 02a Optical Sciences 330 Physical Optics II William J. Dallas January 12, 2005
Matlab Primer Lecture 02a Optical Sciences 330 Physical Optics II William J. Dallas January 12, 2005 Introduction The title MATLAB stands for Matrix Laboratory. This software package (from The Math Works,
More informationIntroduction to MATLAB. Simon O Keefe Non-Standard Computation Group
Introduction to MATLAB Simon O Keefe Non-Standard Computation Group sok@cs.york.ac.uk Content n An introduction to MATLAB n The MATLAB interfaces n Variables, vectors and matrices n Using operators n Using
More informationIntroduction to Matlab. By: Dr. Maher O. EL-Ghossain
Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control
More information10 M-File Programming
MATLAB Programming: A Quick Start Files that contain MATLAB language code are called M-files. M-files can be functions that accept arguments and produce output, or they can be scripts that execute a series
More informationIntroduction to Matlab
Introduction to Matlab Andreas C. Kapourani (Credit: Steve Renals & Iain Murray) 9 January 08 Introduction MATLAB is a programming language that grew out of the need to process matrices. It is used extensively
More informationMATLAB GUIDE UMD PHYS401 SPRING 2011
MATLAB GUIDE UMD PHYS401 SPRING 2011 Note that it is sometimes useful to add comments to your commands. You can do this with % : >> data=[3 5 9 6] %here is my comment data = 3 5 9 6 At any time you can
More informationFlow Control and Functions
Flow Control and Functions Script files If's and For's Basics of writing functions Checking input arguments Variable input arguments Output arguments Documenting functions Profiling and Debugging Introduction
More informationOrdinary Differential Equation Solver Language (ODESL) Reference Manual
Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE
More informationComputer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering
Computer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering 1 Introduction A computer program is a sequence of computer
More informationECE 202 LAB 3 ADVANCED MATLAB
Version 1.2 1 of 13 BEFORE YOU BEGIN PREREQUISITE LABS ECE 201 Labs EXPECTED KNOWLEDGE ECE 202 LAB 3 ADVANCED MATLAB Understanding of the Laplace transform and transfer functions EQUIPMENT Intel PC with
More informationIntroduction to programming in MATLAB
Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html Introduction to programming in MATLAB e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti
More informationSome elements for Matlab programming
Some elements for Matlab programming Nathalie Thomas 2018 2019 Matlab, which stands for the abbreviation of MATrix LABoratory, is one of the most popular language for scientic computation. The classical
More informationMATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c.
MATLAB BASICS Starting Matlab < PC: Desktop icon or Start menu item < UNIX: Enter matlab at operating system prompt < Others: Might need to execute from a menu somewhere Entering Matlab commands < Matlab
More informationSBT 645 Introduction to Scientific Computing in Sports Science #3
SBT 645 Introduction to Scientific Computing in Sports Science #3 SERDAR ARITAN serdar.aritan@hacettepe.edu.tr Biyomekanik Araştırma Grubu www.biomech.hacettepe.edu.tr Spor Bilimleri Fakültesi www.sbt.hacettepe.edu.tr
More informationProgramming in MATLAB
trevor.spiteri@um.edu.mt http://staff.um.edu.mt/trevor.spiteri Department of Communications and Computer Engineering Faculty of Information and Communication Technology University of Malta 17 February,
More informationDesktop Command window
Chapter 1 Matlab Overview EGR1302 Desktop Command window Current Directory window Tb Tabs to toggle between Current Directory & Workspace Windows Command History window 1 Desktop Default appearance Command
More informationCS227-Scientific Computing. Lecture 3-MATLAB Programming
CS227-Scientific Computing Lecture 3-MATLAB Programming Contents of this lecture Relational operators The MATLAB while Function M-files vs script M-files The MATLAB for Logical Operators The MATLAB if
More informationFlow Control. Spring Flow Control Spring / 26
Flow Control Spring 2019 Flow Control Spring 2019 1 / 26 Relational Expressions Conditions in if statements use expressions that are conceptually either true or false. These expressions are called relational
More informationDelphiScript Keywords
DelphiScript Keywords Old Content - visit altium.com/documentation Modified by on 13-Sep-2017 This reference covers the DelphiScript keywords used for the Scripting System in Altium Designer. The scripting
More informationAttia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999
Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999 1999 by CRC PRESS LLC CHAPTER THREE CONTROL STATEMENTS 3.1 FOR
More informationShort Version of Matlab Manual
Short Version of Matlab Manual This is an extract from the manual which was used in MA10126 in first year. Its purpose is to refamiliarise you with the matlab programming concepts. 1 Starting MATLAB 1.1.1.
More informationThe Warhol Language Reference Manual
The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming
More information5. Single-row function
1. 2. Introduction Oracle 11g Oracle 11g Application Server Oracle database Relational and Object Relational Database Management system Oracle internet platform System Development Life cycle 3. Writing
More informationIntroduction to Matlab
Introduction to Matlab UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas, Mike Griffiths & Research Computing Group July 2018 Part 1 - Contents Introducing MATLAB Supported Platforms Obtaining/Accessing
More information1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221
1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221 Functions Recall that an algorithm is a feasible solution to the specific problem. 1 A function is a piece of computer code that accepts
More informationMATLAB GUIDE UMD PHYS375 FALL 2010
MATLAB GUIDE UMD PHYS375 FALL 200 DIRECTORIES Find the current directory you are in: >> pwd C:\Documents and Settings\ian\My Documents\MATLAB [Note that Matlab assigned this string of characters to a variable
More informationMAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB
MATLAB sessions: Laboratory MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs
More informationHow to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands
How to Use MATLAB What is MATLAB MATLAB is an interactive package for numerical analysis, matrix computation, control system design and linear system analysis and design. On the server bass, MATLAB version
More informationDigital Image Processing
Digital Image Processing Introduction to MATLAB Hanan Hardan 1 Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The name MATLAB is an interactive system
More informationIntroduction to MATLAB
Introduction to MATLAB Introduction MATLAB is an interactive package for numerical analysis, matrix computation, control system design, and linear system analysis and design available on most CAEN platforms
More informationMATLAB - FUNCTIONS. Functions can accept more than one input arguments and may return more than one output arguments.
MATLAB - FUNCTIONS http://www.tutorialspoint.com/matlab/matlab_functions.htm Copyright tutorialspoint.com A function is a group of statements that together perform a task. In MATLAB, functions are defined
More informationGRAPHICS AND VISUALISATION WITH MATLAB Part 2
GRAPHICS AND VISUALISATION WITH MATLAB Part 2 UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths March 2012 Topics Handle Graphics Animations Images in Matlab Handle Graphics All Matlab
More informationQuestion Points Score Total 100
Name Signature General instructions: You may not ask questions during the test. If you believe that there is something wrong with a question, write down what you think the question is trying to ask and
More informationWhy use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)
MATLAB(motivation) Why use MATLAB? Mathematcal computations Used a lot for problem solving Statistical Analysis (e.g., mean, min) Visualisation (1D-3D) Signal processing (Fourier transform, etc.) Image
More informationMATLAB GUIDE UMD PHYS401 SPRING 2012
MATLAB GUIDE UMD PHYS40 SPRING 202 We will be using Matlab (or, equivalently, the free clone GNU/Octave) this semester to perform calculations involving matrices and vectors. This guide gives a brief introduction
More informationProgramming for the Web with PHP
Aptech Ltd Version 1.0 Page 1 of 11 Table of Contents Aptech Ltd Version 1.0 Page 2 of 11 Abstraction Anonymous Class Apache Arithmetic Operators Array Array Identifier arsort Function Assignment Operators
More informationELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)
Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies
More informationCOGS 119/219 MATLAB for Experimental Research. Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control
COGS 119/219 MATLAB for Experimental Research Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control .m files We can write the MATLAB commands that we type at the command window
More informationWYSE Academic Challenge Computer Science Test (State) 2013 Solution Set
WYSE Academic Challenge Computer Science Test (State) 2013 Solution Set 1. Correct Answer: E 2's complement systems are often used in computing because negating a number involves simple operations in the
More informationCM0340 Tutorial 2: More MATLAB
CM0340 Tutorial 2: More MATLAB Last tutorial focussed on MATLAB Matrices (Arrays) and vectors which are fundamental to how MATLAB operates in its key application areas including Multimedia data processing
More informationComputer Vision. Matlab
Computer Vision Matlab A good choice for vision program development because Easy to do very rapid prototyping Quick to learn, and good documentation A good library of image processing functions Excellent
More informationScilab Programming. The open source platform for numerical computation. Satish Annigeri Ph.D.
Scilab Programming The open source platform for numerical computation Satish Annigeri Ph.D. Professor, Civil Engineering Department B.V.B. College of Engineering & Technology Hubli 580 031 satish@bvb.edu
More informationMATLAB: The Basics. Dmitry Adamskiy 9 November 2011
MATLAB: The Basics Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 9 November 2011 1 Starting Up MATLAB Windows users: Start up MATLAB by double clicking on the MATLAB icon. Unix/Linux users: Start up by typing
More informationWhat is a Function? EF102 - Spring, A&S Lecture 4 Matlab Functions
What is a Function? EF102 - Spring, 2002 A&S Lecture 4 Matlab Functions What is a M-file? Matlab Building Blocks Matlab commands Built-in commands (if, for, ) Built-in functions sin, cos, max, min Matlab
More informationConditional Control Structures. Dr.T.Logeswari
Conditional Control Structures Dr.T.Logeswari TEST COMMAND test expression Or [ expression ] Syntax Ex: a=5; b=10 test $a eq $b ; echo $? [ $a eq $b] ; echo $? 2 Unix Shell Programming - Forouzan 2 TEST
More informationMATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline
MATLAB Tutorial EE351M DSP Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Kitaek Bae Outline Part I: Introduction and Overview Part II: Matrix manipulations and common functions Part III: Plots
More informationIntroduction to MATLAB
Introduction to MATLAB The Desktop When you start MATLAB, the desktop appears, containing tools (graphical user interfaces) for managing files, variables, and applications associated with MATLAB. The following
More informationIntroduction to MATLAB
Introduction to MATLAB --------------------------------------------------------------------------------- Getting MATLAB to Run Programming The Command Prompt Simple Expressions Variables Referencing Matrix
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationIntroduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis
Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationWhat We Will Learn Today
Lecture Notes 11-19-09 ENGR 0011 - Dr. Lund What we ve learned so far About the MATLAB environment Command Window Workspace Window Current Directory Window History Window How to enter calculations (and
More informationSECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing
SECTION 5: STRUCTURED PROGRAMMING IN MATLAB ENGR 112 Introduction to Engineering Computing 2 Conditional Statements if statements if else statements Logical and relational operators switch case statements
More informationCisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012
Cisco IOS Shell Last Updated: December 14, 2012 The Cisco IOS Shell (IOS.sh) feature provides shell scripting capability to the Cisco IOS command-lineinterface (CLI) environment. Cisco IOS.sh enhances
More informationAn Introduction to Matlab5
An Introduction to Matlab5 Phil Spector Statistical Computing Facility University of California, Berkeley August 21, 2006 1 Background Matlab was originally developed as a simple interface to the LINPACK
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 5: Control Structures II (Repetition) Why Is Repetition Needed? Repetition allows you to efficiently use variables Can input,
More informationConstraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial
1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the
More informationC++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures
More informationColorado State University Department of Mechanical Engineering. MECH Laboratory Exercise #1 Introduction to MATLAB
Colorado State University Department of Mechanical Engineering MECH 417 - Laboratory Exercise #1 Introduction to MATLAB Contents 1) Vectors and Matrices... 2 2) Polynomials... 3 3) Plotting and Printing...
More informationJME Language Reference Manual
JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.
More informationLECTURE 1. What Is Matlab? Matlab Windows. Help
LECTURE 1 What Is Matlab? Matlab ("MATrix LABoratory") is a software package (and accompanying programming language) that simplifies many operations in numerical methods, matrix manipulation/linear algebra,
More informationBEGINNING MATLAB. R.K. Beatson Mathematics Department University of Canterbury. 2 Matlab as a simple matrix calculator 2
BEGINNING MATLAB R.K. Beatson Mathematics Department University of Canterbury Contents 1 Getting started 1 2 Matlab as a simple matrix calculator 2 3 Repeated commands 4 4 Subscripting, rows, columns and
More information