Lab of COMP 406 Introduction of Matlab (III) Programming and Scripts
|
|
- Cameron Williams
- 6 years ago
- Views:
Transcription
1 Lab of COMP 406 Introduction of Matlab (III) Programming and Scripts Teaching Assistant: Pei-Yuan Zhou Contact: Lab 3: 26 Sep.,
2 Open Matlab 2012a Find the Matlab under the folder 1. Y:\Win32\Matlab\R2012a 2. Double click it and open Matlab 2
3 Review 2-D Plots >> plot(x, y) >> xlabel( x ); ylabel( y ) >> legend( x, y ) ; title ( title ) >> bar(x,y); stairs(x,y);errorbar(x,y,e);stem(x,y) 3-D Plots >> meshgrid; mesh(x,y,z);surf(x,y,z) >> peaks(n); colormap(hsv) Subplots >> subplot(row,col,num); 3
4 Lecture and Lab Notes mp406/main.html 4
5 Outline Programming and Scripts Character String Script Functions 5
6 Outline Programming and Scripts Character String Script Functions 6
7 Character String A character string is a sequence of any number of characters enclosed in single quotes. You can assign a string to a variable. Text1 = 'Hello, world'; If the text includes a single quote, use two single quotes within the definition. >>Text2 = 'You''re right' Text2 = You're right Text1 and Text2 are arrays, like all MATLAB variables. Their class or data type is char, which is short for character. (whos) 7
8 Character String You can concatenate strings with square brackets, just as you concatenate numeric arrays. >>Text3 = [Text1,' - ', Text2] Text3 = Hello, world - You're right To convert numeric values to strings, use functions, such as num2str or int2str. f = 71; %fahrenheit degree c = (f-32)/1.8; % centi degree temptext = ['Temperature is ',num2str(c),'c'] temptext = Temperature is C 8
9 Outline Programming and Scripts Character String Script Functions 9
10 Script There are two types of *.m file, Scripts and Functions The simplest type of MATLAB program is called a script. A script is a file with a.m extension that contains multiple sequential lines of MATLAB commands and function calls. 10
11 Script - Creation To create a script, use the edit command. This opens a blank file named newscript.m. >>edit newscript Go to File->New->Script Give a name to script 11
12 Script - Building Typing the sentences in newscript.m Print the value of each elements in the vector x and shows whether they are positive or negative. 12
13 Script - Saving For saving the script, just go to File->Save 13
14 Script - Run If you want to run it, typing >> newscript Then you can see the output in command window like right figure shows. >> newscript x(1) = 1 is positive x(2) = 4 is positive x(3) = -2 is negative or zero x(4) = 3 is positive x(5) = -1 is negative or zero x(6) = -5 is negative or zero 14
15 Script - Run If you want to run it, typing >> newscript And all generated variables are listed in workspace >> newscript x(1) = 1 is positive x(2) = 4 is positive x(3) = -2 is negative or zero x(4) = 3 is positive x(5) = -1 is negative or zero x(6) = -5 is negative or zero 15
16 Script - Comments Whenever you write code, it is a good practice to add comments that describe the code. Comments allow others to understand your code, and can refresh your memory when you return to it later. Add comments using the percentage (%) symbol. n = 50; % 50 data points r = rand(n,1); plot(r) % Draw a line from (0,m) to (n,m) m = mean(r); hold on plot([0,n],[m,m]) hold off title('mean of Random Uniform Data') 16
17 Ex1 Create a script, named as myscript.m The script can draw the plot of function y=sin(x) when x is in [0,2pi] Save your script Run the script 17
18 Ex1 >>edit myscript.m The content of script Save myscript.m myscript x=0:0.1:2*pi; y = sin(x); plot(x,y); 18
19 Script Advantage: Better for Simple but High Repeatability code All generated variables can be stored in workspace easy for viewing Disadvantage: Not support Input/ Output Arguments The variables stored in workspace, which may be covered with each other Function can improve it 19
20 Outline Programming and Scripts Character String Script Functions 20
21 Function A function is a black box that gets some input and produces some output. We do not care about the inner workings of a function. Functions provide reusable code. Functions simplify debugging. Functions have private workspaces: The only variables in the calling program that can be seen by the function are those in the input list. The only variables in the function that can be seen by the calling program are those in the output list. 21
22 Function- Black Box View Param 1 Param 2... Result Param n The black box consists of two parts: the definition of the interface by which the user passes data items to and from the function; and the code block that produces the results required by that interface. 22
23 Function- Black Box View Param 1 Param 2... Result Param n A function definition consists of the following components: A name that follows the same syntactic rules as a variable name; A set of 0 or more parameters provided to the function; Zero or more results to be returned to the called of the function. 23
24 Function Template function <return info> <function name> (<parameters>) <documentation> <code body> % must return the results 1. The <return info> section for most functions involves providing the name(s) of the results returned followed by an = sign. If more than one result is to be returned, they are defined in a vector like container. If nothing is to be returned from this function, both the result list and the = sign are omitted. 2. The <function name> is a name with the same syntactic rules as a variable name, and will be used to invoke the code body. 25
25 Function Template function <return info> <function name> (<parameters>) <documentation> <code body> % must return the results 3. The <parameters> section is a comma-separated list of the names of the data to be provided to the function. 4. The <documentation> section is one or more lines of comments that describe what the function does and how to call it All the documentation lines up to the first non-document line are printed in the command window when you type the following: >> help <function name> The first line is listed next to the file name in the current directory listing 26
26 Function An Example 1. function volume = cylinder(height, radius) 2. % function to compute the volume of a cylinder 3. % volume = cylinder(height, radius) 4. base = pi * radius^2; 5. volume = base * height; Line1: the Matlab function definition is introduced by the key word function, followed by the name of the return variable (if any) and the = sign. Line2: all comments written immediately after the function header are available to the command window when you enter: >> help cylinder 27
27 Function An Example 1. function volume = cylinder(height, radius) 2. % function to compute the volume of a cylinder 3. % volume = cylinder(height, radius) 4. base = pi * radius^2; 5. volume = base * height; Line3: it is a good idea to include in the comments a copy of the function header line to remind a user exactly how to use this function. Line5: you must make at least one assignment to the result variable. The function definition needs no end statement. The code body terminates automatically at the end of the file. 28
28 Function An Example function p = factorial(n) %FACTORIAL Factorial function. % FACTORIAL(N) is the product of all the name integers of function from 1 to N, % i.e. prod(1:n). Since double precision numbers only have about % 15 digits, the answer is only accurate for N <= 21. For larger N, % the answer will have the right magnitude, input and argument is accurate for % the first 15 digits. % % See also PROD. % Copyright The MathWorks, Inc. % $Revision: 1.5 $ if (length(n)~=1) (fix(n) ~= n) (n < 0) error('n must be a positive integer'); end p = prod(1:n); other comment lines output argument H1 comment line executable code 29
29 Function Create A Function 1. >> edit function1 % create a function1.m file 2. type the code in the file function average = function1(vector) average = sum(vector)/length(vector); 3. save file function1.m 4. View your function code : >>type function1.m 5. call the function: >>vector = [1 5 3] >>ave = function1(vector) 30
30 Function Create A Function 6. Adding Help & Comments for function function average = function1(vector) % FUNCTION1: A simple function with a single help line. % % Usage of this function: % output = function1(input) % "output" is the average of the input vector "input". % Pei-Yuan, 2014/09/26. average = sum(vector)/length(vector); % calculate average 31
31 Function Create A Function After creating function, the comments (starting from percent (%) symbol) are the content of help Type help + function name, you can see the help documentation you added >> help function1 FUNCTION1: A simple function with a single help line. Usage of this function: output = function1(input) "output" is the average of the input vector "input". 32
32 Function *Maximum identifier Length 1. The maximum identifier length is 63. len = namelengthmax => returns the maximum length allowed for MATLAB identifiers. The maximum identifier length is different for different version of MATLAB 2. The name of function can be different from name of M-file. (It is better to use the same name) The name of M-file is used for calling function 33
33 Function Input and Output A function can have multiple inputs and outputs The following func2 has two inputs and two outputs function [ave1, ave2] = func2(vector1, vector2); ave1 = sum(vector1)/length(vector1); ave2 = sum(vector2)/length(vector2); Run func3.m >> [a,b] = func3 ([1 2 3], [ ]) 34
34 Function Input and Output nargin and nargout can be used to control the number of inputs and outputs. nargin: returns the number of input arguments that were used to call the function. nargout: returns the number of output arguments that were used to call the function 35
35 Function Input and Output Then you can change the func2.m into func3.m function [ave1, ave2] = func4(vector1, vector2) if nargin == 1, % only one input ave1 = sum(vector1)/length(vector1); end if nargout == 2, % two outputs ave1 = sum(vector1)/length(vector1); ave2 = sum(vector2)/length(vector2); end 36
36 Function Input and Output Then you can change the func2.m into func3.m >> [a, b] = func4([1 2 3], [ ]) a = 2 b = 6 >> c = func4([ ]) c = 5 The output is different based on different calling method 37
37 Function Nested Function function out = func4(x) r = reciproc(x); out = sum(r); >> func4([1 2 3]) ans = % Definition for subfunctions function output = reciproc(input) output = 1./input; Calculate the sum of reciprocal of all elements in vector 38
38 Ex1 Problem: write a function called strsearch that takes a string s and a character c, and returns the number of occurrences of c in s and the index of the first occurrence. Hint & Pseudo code: Function [cnt, pos] = strsearch( s, c) For each character of s in reverse order If character is equal to c increment the counter save the index 39
39 Ex1 - answer function [ cnt, pos ] = strsearch( s, c ) %STRSEARCH find the number of occurrences of a character in a string pos = 0; cnt = 0; n = length(s); for i = n:-1:1, % from n to 1, and minus 1 for each loop if ( s(i) == c ), cnt = cnt + 1; pos = i; end end 40
40 Ex1 - answer [ a, b ] = strsearch( 'abccdecfac', 'c' ) a = 4 b = 3 a = strsearch( 'abccdecfac', 'c' ) a = 4 strsearch( 'abccdecfac', 'c' ) ans = 4 41
41 Ex2 Nested Function Problem: write a function called mystats that find mean and median with internal functions. Hint: Creation: function [avg, med] = mystats(u) The functions you can use: avg = mean(u,n) % u is the vector, n is the length of u med = median (u,n) 42
42 Ex2 - answer function [avg, med] = mystats(u) %MYSTATS Find mean and median with internal functions. n = length(u); avg = mean(u,n); med = median(u,n); function a = mean(v,n) % Subfunction to calculate average. a = sum(v)/n; function m = median(v,n) % Subfunction to 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 43
43 Ex2 - answer >> [a,m]=newscript([ ]) a = m = >> [a,m]=newscript([ ]) a = m =
44 Summary Both scripts and functions are saved as m-files. Functions are special m-files that receive data through input arguments and return results through output arguments. Scripts are just a collection of MATLAB statements. Functions are defined by the function statement in the first line. Scripts use the global workspace but functions have their own local independent workspaces. 45
45 Contact: Lab 3: 26 Sep.,
INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD. July 2018
INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths July 2018 Outline MATLAB Scripts Relational Operations Program Control Statements Writing
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 informationIntroduction 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 informationLaboratory 1 Octave Tutorial
Signals, Spectra and Signal Processing Laboratory 1 Octave Tutorial 1.1 Introduction The purpose of this lab 1 is to become familiar with the GNU Octave 2 software environment. 1.2 Octave Review All laboratory
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 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. 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 informationLab of COMP 406 Introduction of Matlab (II) Graphics and Visualization
Lab of COMP 406 Introduction of Matlab (II) Graphics and Visualization Teaching Assistant: Pei-Yuan Zhou Contact: cspyzhou@comp.polyu.edu.hk Lab 2: 19 Sep., 2014 1 Review Find the Matlab under the folder
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 informationCSE/NEUBEH 528 Homework 0: Introduction to Matlab
CSE/NEUBEH 528 Homework 0: Introduction to Matlab (Practice only: Do not turn in) Okay, let s begin! Open Matlab by double-clicking the Matlab icon (on MS Windows systems) or typing matlab at the prompt
More informationIntroduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003
Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 About MATLAB MATLAB (MATrix LABoratory) is a high level language made for: Numerical Computation (Technical computing)
More informationIntroduction to MATLAB LAB 1
Introduction to MATLAB LAB 1 1 Basics of MATLAB MATrix LABoratory A super-powerful graphing calculator Matrix based numeric computation Embedded Functions Also a programming language User defined functions
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 informationIntroduction to Matlab
Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing
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 informationIntroduction to MATLAB
ELG 3125 - Lab 1 Introduction to MATLAB TA: Chao Wang (cwang103@site.uottawa.ca) 2008 Fall ELG 3125 Signal and System Analysis P. 1 Do You Speak MATLAB? MATLAB - The Language of Technical Computing ELG
More informationIntroduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College
Introduction to Matlab to Accompany Linear Algebra Douglas Hundley Department of Mathematics and Statistics Whitman College August 27, 2018 2 Contents 1 Getting Started 5 1.1 Before We Begin........................................
More informationTentative Course Schedule, CRN INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 LECTURE # 5 INLINE FUNCTIONS
Tentative Course Schedule, CRN 24023 INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 Dr. S. Gökhan Technical University of Istanbul Week Date Topics 1 Feb. 08 Computing 2 Feb. 15
More informationMATLAB TUTORIAL WORKSHEET
MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent
More informationSTAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial
STAT/MATH 395 A - PROBABILITY II UW Winter Quarter 2016 Néhémy Lim Matlab Tutorial 1 Introduction Matlab (standing for matrix laboratory) is a high-level programming language and interactive environment
More information12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.
Example 4 Printing and Plotting Matlab provides numerous print and plot options. This example illustrates the basics and provides enough detail that you can use it for typical classroom work and assignments.
More informationMatlab Tutorial and Exercises for COMP61021
Matlab Tutorial and Exercises for COMP61021 1 Introduction This is a brief Matlab tutorial for students who have not used Matlab in their programming. Matlab programming is essential in COMP61021 as a
More informationGetting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text
Chapter 1 Getting Started How to Get Matlab Matlab physically resides on each of the computers in the Olin Hall labs. See your instructor if you need an account on these machines. If you are going to go
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 informationMATLAB. MATLAB Review. MATLAB Basics: Variables. MATLAB Basics: Variables. MATLAB Basics: Subarrays. MATLAB Basics: Subarrays
MATLAB MATLAB Review Selim Aksoy Bilkent University Department of Computer Engineering saksoy@cs.bilkent.edu.tr MATLAB Basics Top-down Program Design, Relational and Logical Operators Branches and Loops
More informationComputer Programming in MATLAB
Computer Programming in MATLAB Prof. Dr. İrfan KAYMAZ Engineering Faculty Department of Mechanical Engineering Arrays in MATLAB; Vectors and Matrices Graphing Vector Generation Before graphing plots in
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 informationCSCI 6906: Fundamentals of Computational Neuroimaging. Thomas P. Trappenberg Dalhousie University
CSCI 6906: Fundamentals of Computational Neuroimaging Thomas P. Trappenberg Dalhousie University 1 Programming with Matlab This chapter is a brief introduction to programming with the Matlab programming
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 informationMechanical Engineering Department Second Year (2015)
Lecture 7: Graphs Basic Plotting MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. This section describes a few of the most
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 informationIntroduction to MATLAB
Quick Start Tutorial Introduction to MATLAB Hans-Petter Halvorsen, M.Sc. What is MATLAB? MATLAB is a tool for technical computing, computation and visualization in an integrated environment. MATLAB is
More informationAMS 27L LAB #2 Winter 2009
AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles
More informationAn Introduction to MATLAB II
Lab of COMP 319 An Introduction to MATLAB II Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 2: 16th Sep, 2013 1 Outline of Lab 2 Review of Lab 1 Matrix in Matlab
More informationLab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013
Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1 Where is Matlab? Find the Matlab under the folder 1.
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 informationSignals and Systems Profs. Byron Yu and Pulkit Grover Fall Homework 1
18-290 Signals and Systems Profs. Byron Yu and Pulkit Grover Fall 2018 Homework 1 This homework is due in class on Thursday, September 6, 9:00am. Instructions Solve all non-matlab problems using only paper
More informationMATLAB Functions and Graphics
Functions and Graphics We continue our brief overview of by looking at some other areas: Functions: built-in and user defined Using M-files to store and execute statements and functions A brief overview
More informationComputing Fundamentals Plotting
Computing Fundamentals Plotting Salvatore Filippone salvatore.filippone@uniroma2.it 2014 2015 (salvatore.filippone@uniroma2.it) Plotting 2014 2015 1 / 14 Plot function The basic function to plot something
More informationAppendix A. Introduction to MATLAB. A.1 What Is MATLAB?
Appendix A Introduction to MATLAB A.1 What Is MATLAB? MATLAB is a technical computing environment developed by The Math- Works, Inc. for computation and data visualization. It is both an interactive system
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 informationMATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University
MATLAB Fundamentals Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University Reference: 1. Applied Numerical Methods with MATLAB for Engineers, Chapter 2 &
More informationCourse Layout. Go to https://www.license.boun.edu.tr, follow instr. Accessible within campus (only for the first download)
Course Layout Lectures 1: Variables, Scripts and Operations 2: Visualization and Programming 3: Solving Equations, Fitting 4: Images, Animations, Advanced Methods 5: Optional: Symbolic Math, Simulink Course
More informationWhat is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations
What is MATLAB? It stands for MATrix LABoratory It is developed by The Mathworks, Inc (http://www.mathworks.com) It is an interactive, integrated, environment for numerical computations for symbolic computations
More informationExperiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?
Experiment 1: Introduction to MATLAB I Introduction MATLAB, which stands for Matrix Laboratory, is a very powerful program for performing numerical and symbolic calculations, and is widely used in science
More informationPlotting - Practice session
Plotting - Practice session Alessandro Fanfarillo - Salvatore Filippone fanfarillo@ing.uniroma2.it May 28th, 2013 (fanfarillo@ing.uniroma2.it) Plotting May 28th, 2013 1 / 14 Plot function The basic function
More informationDEPARTMENT OF MATHS, MJ COLLEGE
T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,
More informationThis module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in
This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in subsequent modules to help to teach research related concepts
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 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 informationNumerical Methods in Engineering Sciences
Numerical Methods in Engineering Sciences Lecture 1: Brief introduction to MATLAB Pablo Antolin pablo.antolinsanchez@unipv.it October 29th 2013 How many of you have used MATLAB before? How many of you
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 informationMATLAB Lecture 4. Programming in MATLAB
MATLAB Lecture 4. Programming in MATLAB In this lecture we will see how to write scripts and functions. Scripts are sequences of MATLAB statements stored in a file. Using conditional statements (if-then-else)
More information2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command...
Contents 2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command... 9 2D LINE PLOTS One of the benefits of programming in MATLAB
More informationMathworks (company that releases Matlab ) documentation website is:
1 Getting Started The Mathematics Behind Biological Invasions Introduction to Matlab in UNIX Christina Cobbold and Tomas de Camino Beck as modified for UNIX by Fred Adler Logging in: This is what you do
More informationMatlab Tutorial for COMP24111 (includes exercise 1)
Matlab Tutorial for COMP24111 (includes exercise 1) 1 Exercises to be completed by end of lab There are a total of 11 exercises through this tutorial. By the end of the lab, you should have completed the
More informationBasic Plotting. All plotting commands have similar interface: Most commonly used plotting commands include the following.
2D PLOTTING Basic Plotting All plotting commands have similar interface: y-coordinates: plot(y) x- and y-coordinates: plot(x,y) Most commonly used plotting commands include the following. plot: Draw a
More informationIntroduction to MATLAB Practical 1
Introduction to MATLAB Practical 1 Daniel Carrera November 2016 1 Introduction I believe that the best way to learn Matlab is hands on, and I tried to design this practical that way. I assume no prior
More informationA very brief Matlab introduction
A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading
More information1 Introduction to Matlab
1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,
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 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 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 informationFondamenti di Informatica
Fondamenti di Informatica Scripts and Functions lesson 8 2012/04/12 Prof. Emiliano Casalicchio emiliano.casalicchio@uniroma2.it Agenda n Matlab scripts examples n Matlab functions differences with script
More informationEE 301 Signals & Systems I MATLAB Tutorial with Questions
EE 301 Signals & Systems I MATLAB Tutorial with Questions Under the content of the course EE-301, this semester, some MATLAB questions will be assigned in addition to the usual theoretical questions. This
More informationLecture 4: Complex Numbers Functions, and Data Input
Lecture 4: Complex Numbers Functions, and Data Input Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 3. What is a Function? A
More informationENGR Fall Exam 1
ENGR 13100 Fall 2012 Exam 1 INSTRUCTIONS: Duration: 60 minutes Keep your eyes on your own work! Keep your work covered at all times! 1. Each student is responsible for following directions. Read carefully.
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 informationLecture 15 MATLAB II: Conditional Statements and Arrays
Lecture 15 MATLAB II: Conditional Statements and Arrays 1 Conditional Statements 2 The boolean operators in MATLAB are: > greater than < less than >= greater than or equals
More informationIntroduction to GNU-Octave
Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016
More informationMatlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:
1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write
More informationLab 8: Conditional Statements with Multiple Branches (please develop programs individually)
ENGR 128 Computer Lab Lab 8: Conditional Statements with Multiple Branches (please develop programs individually) I. Background: Multiple Branching and the if/if/ structure Many times we need more than
More informationGetting started with MATLAB
Getting started with MATLAB You can work through this tutorial in the computer classes over the first 2 weeks, or in your own time. The Farber and Goldfarb computer classrooms have working Matlab, but
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 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 informationDSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab
Islamic University of Gaza Faculty of Engineering Electrical Engineering Department 2012 DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab Goals for this Lab Assignment: In this lab we would have
More informationHomework 1 Description CmpE 362 Spring Instructor : Fatih Alagoz Teaching Assistant : Yekta Said Can Due: 3 March, 23:59, sharp
Homework 1 Description CmpE 362 Spring 2016 Instructor : Fatih Alagoz Teaching Assistant : Yekta Said Can Due: 3 March, 23:59, sharp Homework 1 This homework is designed to teach you to think in terms
More informationLecture 6 MATLAB programming (4) Dr.Qi Ying
Lecture 6 MATLAB programming (4) Dr.Qi Ying Objectives User-defined Functions Anonymous Functions Function name as an input argument Subfunctions and nested functions Arguments persistent variable Anonymous
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 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 informationAn Introductory Guide to MATLAB
CPSC 303 An Introductory Guide to MATLAB Ian Cavers Department of Computer Science University of British Columbia 99W T2 1 Introduction MATLAB provides a powerful interactive computing environment for
More informationMath 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)
Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau) January 24, 2010 Starting Under windows Click on the Start menu button
More informationMATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.
MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationWhat is MATLAB and howtostart it up?
MAT rix LABoratory What is MATLAB and howtostart it up? Object-oriented high-level interactive software package for scientific and engineering numerical computations Enables easy manipulation of matrix
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 informationUser-defined Functions
User-defined Functions >> x = 19; >> y = sqrt (x); sqrt is a built-in function Somewhere there is a file called sqrt.m that contains all the code to compute sine It would be a pain to write that yourself
More informationIntroduction to MATLAB
Introduction to MATLAB Chen Huang Computer Science and Engineering SUNY at Buffalo What is MATLAB? MATLAB (stands for matrix laboratory ) It is a language and an environment for technical computing Designed
More informationMATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras
MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras Module No. #01 Lecture No. #1.1 Introduction to MATLAB programming
More informationToday s topics. Announcements/Reminders: Characters and strings Review of topics for Test 1
Today s topics Characters and strings Review of topics for Test 1 Announcements/Reminders: Assignment 1b due tonight 11:59pm Test 1 in class on Thursday Characters & strings We have used strings already:
More informationChapter 1 MATLAB Preliminaries
Chapter 1 MATLAB Preliminaries 1.1 INTRODUCTION MATLAB (Matrix Laboratory) is a high-level technical computing environment developed by The Mathworks, Inc. for mathematical, scientific, and engineering
More informationIntroduction to Matlab
What is Matlab? Introduction to Matlab Matlab is software written by a company called The Mathworks (mathworks.com), and was first created in 1984 to be a nice front end to the numerical routines created
More informationIntroduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018)
Introduction to MATLAB Programming Chapter 3 Linguaggio Programmazione Matlab-Simulink (2017/2018) Algorithms An algorithm is the sequence of steps needed to solve a problem Top-down design approach to
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 informationBasic MATLAB Intro III
Basic MATLAB Intro III Plotting Here is a short example to carry out: >x=[0:.1:pi] >y1=sin(x); y2=sqrt(x); y3 = sin(x).*sqrt(x) >plot(x,y1); At this point, you should see a graph of sine. (If not, go to
More informationFunctions in C C Programming and Software Tools. N.C. State Department of Computer Science
Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the
More informationFunctions in C C Programming and Software Tools
Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the
More informationMATLAB Primer. R2016b
MATLAB Primer R26b How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral Technical support: www.mathworks.com/support/contact_us
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 informationMAT 275 Laboratory 1 Introduction to MATLAB
MATLAB sessions: Laboratory 1 1 MAT 275 Laboratory 1 Introduction to MATLAB MATLAB is a computer software commonly used in both education and industry to solve a wide range of problems. This Laboratory
More information