MATLAB Operators, control flow and scripting. Edited by Péter Vass

Size: px
Start display at page:

Download "MATLAB Operators, control flow and scripting. Edited by Péter Vass"

Transcription

1 MATLAB Operators, control flow and scripting Edited by Péter Vass

2 Operators An operator is a symbol which is used for specifying some kind of operation to be executed. An operator is always the member of an expression and refers to at least one but mostly two operands. An operand can be a variable, a constant or an embedded expression between a pair of round brackets. An expression is made up of variables, operators Operators in the MATLAB is designed to work not only on scalars but also on matrices and arrays. The following groups of operators are distinguished in the MATLAB: arithmetic operators, relational operators, logical operators, bitwise operators, set operators.

3 Operators Most of the arithmetic operators together with matrices and arrays have already been introduced. Relational operators They are used for comparing two operands in an expression. The result of the comparison is a logical value. There are only two different logical values: 0 which means "false", 1 which corresponds "true" If the operands are not scalars but vectors or matrices, the comparison is performed element by element. So, the result of a relational expression will be a vector or matrix of logical values.

4 Operators operator meaning < less than <= less than or equal to > greater than >= greater than or equal to == equal to ~= not equal to Example: >>a = 10; >>b = 20; >>a >= b >>a~=b

5 Logical operators Operators The results of the logical operations are always logical values (true or false, that is 1 or 0) There are two types of logical operators in the MATLAB element-wise logical operators, short-circuit logical operators. Element-wise logical operators Their operands are vectors or matrices. All numbers hold "true" boolean value, except for 0 itself which is "false". The logical operation is performed element by element. operator & logical operation AND OR ~ NOT

6 Truth table of logical AND a b a & b Operators Truth table of logical OR Truth table of logical NOT a b a b a ~a

7 Example >> X=round(10*rand(2,3)) >> Y=eye(2,3) >> X&Y >> X Y >> ~Y Operators Remark: the dimensions of the operands must fit. Try the floor and ceil functions instead of round. floor(x) rounds down the elements of X to the nearest integers. ceil(x) rounds up the elements of X to the nearest integers. round(x) rounds the elements of X to the nearest integers.

8 Short-circuit logical operators Operators The operands of these operators are scalars and/or logical expressions (not vectors an matrices). The result of an evaluated logical expression is a logical value. The attribute "short-circuit" is related to the way of evaluation of an expression with logical AND operation (expr1 AND expr2). When the right side of the expression is "false", the left side of the expression will not be evaluated and the result will be "false" (see the truth table of AND operation). In such a way, the evaluation of the expression shortens. operator && logical operation AND OR

9 Operators Example >>x=5; >>y=0; >>(y~=0) && (x>2) Both the relational and logical operators are primarily used in conditional expressions of different control statements (if, while etc.) The application of different control statements are connected to programming in MATLAB language.

10 Script It was shown that MATLAB works as a high-performance calculator which is able to execute the commands entered by the user. However, MATLAB can also be used for programming because it provides a powerful programming language, as well as an interactive computational environment. In the MATLAB terminology, a source code of a program called script. So, the activity of writing a program is often mentioned as scripting. Script is a program file with.m extension and it contains a series of commands. Unlike a function, it does not accept inputs and does not return any output. But, it can use the variables existing in the actual workspace in its specified computations. In addition, the new variables created by the script remain in the workspace, so we can use them in later computations.

11 Script Creating a script file A script file can be created in any text editor, but it is suggested using the built-in MATLAB editor. The MATLAB editor can be opened in two ways: from the command line by typing the command edit or edit filename, from the tool bar of the MATLAB GUI by choosing New Script or New Script on the Home tab. Typing and saving the code of the script We can use variables, constants, different types of expressions, commands, function calls, control structures etc. After the % symbol, a line of text as a comment can be inserted in the code. The comment line is not interpreted by the MATLAB Do not forget to save the script.

12 Script Example x = 0:pi/20:2*pi; y = sin(x); plot(x,y); Running the script After typing and saving the code, the script can be executed by means of typing its name without m extension in the command line and pressing enter key, or clicking the Run command on the tool bar of the MATLAB editor. If you modify something in the code, do not forget to save its content before running.

13 Control statements Decision making statements They are used for implementing conditional branches in the program. Simple conditional execution if expression

14 Two-way branching if expression else Control statements Multiway branching if expression_1 elseif expression_2 else

15 Example Control statements a = 100; if a == 10 fprintf('value of a is 10\n' ); elseif( a == 20 ) fprintf('value of a is 20\n' ); elseif a == 30 fprintf('value of a is 30\n' ); else fprintf('none of the values are matching\n'); fprintf('exact value of a is: %d\n', a );

16 Control statements Nested decison making statements if expression_1 if expression_2 else

17 Control statements Multiway branching with switch statement switch switch_expression case case_expression_1 case case_expression_ otherwise

18 mark = 4; switch(mark) case 5 fprintf('excellent\n' ); case 4 fprintf('good' ); case 3 fprintf('medium' ); case 2 fprintf('passed' ); case 1 fprintf('failed' ); otherwise fprintf('invalid mark\n' ); Control statements

19 Control statements Loop statements Loops are used to execute a block of code several number of times. The number of repetition is determined by the loop condition. While loop The while loop repeatedly executes statements while the loop condition (expression) is true. while expression

20 Example a = 10; % while loop execution while( a < 20 ) fprintf('value of a= %d\n', a); a = a + 1; Control statements

21 Control statements For loop The for loop is a control structure by which the number of repetition can be specified directly. for index = values The values part of the statement which specifies the number of repetition is generally given in the following two forms: initval : val The value of the loop control variable starts with initval, and it is increased by 1 after each repetition of the instruction block. The process continues while its value is less than or equal to val.

22 Control statements initval:step:val The value of the loop control variable starts with initval, and it is increased by the value of step after each repetition of the instruction block. The process continues while its value is less than or equal to val. If the initval is greater than the val and the step is a negative value, the control loop variable is not increased but decreased.

23 Example 1 for a = 5:10 fprintf('value of a: %d\n', a); Control statements Example 2 for a = 5: -0.5: 2 disp(a)

24 Control statements Nested loops are also used in programming practice while expression_1 while expression_2 for index1 = values1 for index2 = values2

25 Control statements Special control statements They are used in loops for modifying the normal execution of the loops. The break statement It terminates the execution of a loop if a certain condition is fulfilled. Example a = 10; while (a < 20 ) fprintf('value of a: %d\n', a); a = a+1; if( a > 15) break;

26 Control statements The continue statement It is used for skipping the actual iteration of a loop if a certain condition is fulfilled. The execution of the loop continues with the next iteration. Example a = 10; while a < 20 if a == 15 a = a + 1; continue; fprintf('value of a: %d\n', a); a = a + 1;

EL2310 Scientific Programming

EL2310 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 information

EL2310 Scientific Programming

EL2310 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 information

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Constraint-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 information

function [s p] = sumprod (f, g)

function [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 information

An Introduction to MATLAB

An Introduction to MATLAB An Introduction to MATLAB Day 1 Simon Mitchell Simon.Mitchell@ucla.edu High level language Programing language and development environment Built-in development tools Numerical manipulation Plotting of

More information

Chapter 7: Programming in MATLAB

Chapter 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 information

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

Flow of Control. Flow of control The order in which statements are executed. Transfer of control 1 Programming in C Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed Programming in C 1 Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

Chapter 1 Introduction to MATLAB

Chapter 1 Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 What is MATLAB? MATLAB = MATrix LABoratory, the language of technical computing, modeling and simulation, data analysis and processing, visualization and graphics,

More information

Selection Statements

Selection Statements Selection Statements by Ahmet Sacan selection statements, branching statements, condition, relational expression, Boolean expression, logical expression, relational operators, logical operators, truth

More information

Chapter 4: Programming with MATLAB

Chapter 4: Programming with MATLAB Chapter 4: Programming with MATLAB Topics Covered: Programming Overview Relational Operators and Logical Variables Logical Operators and Functions Conditional Statements For Loops While Loops Debugging

More information

Introduction to MATLAB

Introduction 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 information

COGS 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 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 information

Programming for Experimental Research. Flow Control

Programming 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 information

MATLAB TUTORIAL WORKSHEET

MATLAB 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 information

Flow Control: Branches and loops

Flow Control: Branches and loops Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the

More information

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28 Control Structures Dr. Mihail March 1, 2015 (Dr. Mihail) Control March 1, 2015 1 / 28 Overview So far in this course, MATLAB programs consisted of a ordered sequence of mathematical operations, functions,

More information

Desktop Command window

Desktop 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 information

Relational & Logical Operators, Selection Statements

Relational & Logical Operators, Selection Statements Relational & Logical Operators, Selection Statements by Ahmet Sacan selection statements, branching statements, condition, relational expression, Boolean expression, logical expression, relational operators,

More information

Chapter 4. Flow of Control

Chapter 4. Flow of Control Chapter 4. Flow of Control Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr Sequential flow of control

More information

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4. Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

More information

MATLAB. Devon Cormack and James Staley

MATLAB. Devon Cormack and James Staley MATLAB Devon Cormack and James Staley MATrix LABoratory Originally developed in 1970s as a FORTRAN wrapper, later rewritten in C Designed for the purpose of high-level numerical computation, visualization,

More information

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction 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 information

Compact Matlab Course

Compact Matlab Course Compact Matlab Course MLC.1 15.04.2014 Matlab Command Window Workspace Command History Directories MLC.2 15.04.2014 Matlab Editor Cursor in Statement F1 Key goes to Help Information MLC.3 15.04.2014 Elementary

More information

C/C++ Programming for Engineers: Matlab Branches and Loops

C/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 information

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Ordinary 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 information

7 Control Structures, Logical Statements

7 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 information

Stokes Modelling Workshop

Stokes Modelling Workshop Stokes Modelling Workshop 14/06/2016 Introduction to Matlab www.maths.nuigalway.ie/modellingworkshop16/files 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 1 / 16 Matlab As part of this crash

More information

Computer 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 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 information

Lecture 3 MATLAB programming (1) Dr.Qi Ying

Lecture 3 MATLAB programming (1) Dr.Qi Ying Lecture 3 MATLAB programming (1) Dr.Qi Ying Objectives Data types Logical operators/functions Branching Debugging of a program Data types in MATLAB Basic: Numeric (integer, floating-point, complex) Logical:

More information

Getting started with MATLAB

Getting 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 information

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction 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 information

Scientific Computing with MATLAB

Scientific Computing with MATLAB Scientific Computing with MATLAB Dra. K.-Y. Daisy Fan Department of Computer Science Cornell University Ithaca, NY, USA UNAM IIM 2012 2 Focus on computing using MATLAB Computer Science Computational Science

More information

MATLAB BASICS. Macro II. February 25, T.A.: Lucila Berniell. Macro II (PhD - uc3m) MatLab Basics 02/25/ / 15

MATLAB BASICS. Macro II. February 25, T.A.: Lucila Berniell. Macro II (PhD - uc3m) MatLab Basics 02/25/ / 15 MATLAB BASICS Macro II T.A.: Lucila Berniell February 25, 2010 Macro II (PhD - uc3m) MatLab Basics 02/25/2010 1 / 15 MATLAB windows Macro II (PhD - uc3m) MatLab Basics 02/25/2010 2 / 15 Numbers, vectors

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

More information

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk Control Statements ELEC 206 Prof. Siripong Potisuk 1 Objectives Learn how to change the flow of execution of a MATLAB program through some kind of a decision-making process within that program The program

More information

Mini-Matlab Lesson 5: Functions and Loops

Mini-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 information

Selection Statements. Chapter 4. Copyright 2013 Elsevier Inc. All rights reserved 1

Selection Statements. Chapter 4. Copyright 2013 Elsevier Inc. All rights reserved 1 Selection Statements Chapter 4 Copyright 2013 Elsevier Inc. All rights reserved 1 Recall Relational Expressions The relational operators in MATLAB are: > greater than < less than >= greater than or equals

More information

MATLAB for Chemical engineer

MATLAB for Chemical engineer University of Baghdad College of Engineering Department of Chemical Engineering MATLAB for Chemical engineer Basic and Applications Lecture No. 9 Dr. Mahmood Khazzal Hummadi Samar Kareem 2016 Lecture No.

More information

Arithmetic operations

Arithmetic operations Arithmetic operations Add/Subtract: Adds/subtracts vectors (=> the two vectors have to be the same length). >> x=[1 2]; >> y=[1 3]; >> whos Name Size Bytes Class Attributes x 1x2 16 double y 1x2 16 double

More information

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017 SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful

More information

Computers and FORTRAN Language Fortran 95/2003. Dr. Isaac Gang Tuesday March 1, 2011 Lecture 3 notes. Topics:

Computers and FORTRAN Language Fortran 95/2003. Dr. Isaac Gang Tuesday March 1, 2011 Lecture 3 notes. Topics: Computers and FORTRAN Language Fortran 95/2003 Dr. Isaac Gang Tuesday March 1, 2011 Lecture 3 notes Topics: - Program Design - Logical Operators - Logical Variables - Control Statements Any FORTRAN program

More information

Relational and Logical Operators. MATLAB Laboratory 10/07/10 Lecture. Chapter 7: Flow Control in Programs. Examples. Logical Operators.

Relational and Logical Operators. MATLAB Laboratory 10/07/10 Lecture. Chapter 7: Flow Control in Programs. Examples. Logical Operators. Relational and Logical Operators MATLAB Laboratory 10/07/10 Lecture Chapter 7: Flow Control in Programs Both operators take on form expression1 OPERATOR expression2 and evaluate to either TRUE (1) or FALSE

More information

Lab 0a: Introduction to MATLAB

Lab 0a: Introduction to MATLAB http://www.comm.utoronto.ca/~dkundur/course/real-time-digital-signal-processing/ Page 1 of 1 Lab 0a: Introduction to MATLAB Professor Deepa Kundur Introduction and Background Welcome to your first real-time

More information

Chapter 8 Statement-Level Control Structures

Chapter 8 Statement-Level Control Structures Chapter 8 Statement-Level Control Structures In Chapter 7, the flow of control within expressions, which is governed by operator associativity and precedence rules, was discussed. This chapter discusses

More information

MATLAB Laboratory 10/07/10 Lecture. Chapter 7: Flow Control in Programs

MATLAB Laboratory 10/07/10 Lecture. Chapter 7: Flow Control in Programs MATLAB Laboratory 10/07/10 Lecture Chapter 7: Flow Control in Programs Lisa A. Oberbroeckling Loyola University Maryland loberbroeckling@loyola.edu L. Oberbroeckling (Loyola University) MATLAB 10/07/10

More information

Branches, Conditional Statements

Branches, Conditional Statements Branches, Conditional Statements Branches, Conditional Statements A conditional statement lets you execute lines of code if some condition is met. There are 3 general forms in MATLAB: if if/else if/elseif/else

More information

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services MATLAB INTRODUCTION Risk analysis lab 2018 2018. szeptember 10., Budapest Ceffer Attila PhD student BUTE Department Of Networked Systems and Services ceffer@hit.bme.hu Előadó képe MATLAB Introduction 2

More information

Linear Algebra and MATLAB

Linear Algebra and MATLAB Linear Algebra and MATLAB Pre-Semester Course Mathematics Christian Seckinger Christian.Seckinger@hof.uni-frankfurt.de MATLAB 1 1 This script is based on a MATLAB course of Alexey Cherepnev and Tobias

More information

4.0 Programming with MATLAB

4.0 Programming with MATLAB 4.0 Programming with MATLAB 4.1 M-files The term M-file is obtained from the fact that such files are stored with.m extension. M-files are alternative means of performing computations so as to expand MATLAB

More information

Chapter 4: Basic C Operators

Chapter 4: Basic C Operators Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional

More information

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions. Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate

More information

Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.

Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved. Internet & World Wide Web How to Program, 5/e Sequential execution Execute statements in the order they appear in the code Transfer of control Changing the order in which statements execute All scripts

More information

Advanced features of the Calculate signal tool

Advanced features of the Calculate signal tool Advanced features of the Calculate signal tool Case study: how to us the advanced features of the Calculate signal tool? 1 The calculate signal tool The calculate signal tool is one of the most useful

More information

Short Introduction into MATLAB

Short Introduction into MATLAB Short Introduction into MATLAB Christian Schulz christian.schulz@cma.uio.no CMA/IFI - UiO 1. Basics Startup Variables Standard Operations 2. Next Steps Plots Built in Functions Write/Plot to File 3. Programming

More information

What is Matlab? The command line Variables Operators Functions

What is Matlab? The command line Variables Operators Functions What is Matlab? The command line Variables Operators Functions Vectors Matrices Control Structures Programming in Matlab Graphics and Plotting A numerical computing environment Simple and effective programming

More information

FOR LOOP. for <indexmin:indexstep:indexmax> {statements} end

FOR LOOP. for <indexmin:indexstep:indexmax> {statements} end FOR LOOP for {statements} Exercise: Define a vector z R 10 (= R 10 1 ) s.t. z j = 2 j for j = 1,...,10. Solution. Create a new script wiht the following instructions: for

More information

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction 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 information

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB

SECTION 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 information

Arithmetic and Logic Blocks

Arithmetic and Logic Blocks Arithmetic and Logic Blocks The Addition Block The block performs addition and subtractions on its inputs. This block can add or subtract scalar, vector, or matrix inputs. We can specify the operation

More information

Introduction to programming in MATLAB

Introduction 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 information

Control structures and logic

Control structures and logic Programming with Java Module 2 Control structures and logic Theoretical part Contents 1 Module overview 3 1.1 Commands and blocks........................... 3 2 Operators (Part II) 4 2.1 Relational Operators............................

More information

JME Language Reference Manual

JME 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 information

Programming in MATLAB Part 2

Programming in MATLAB Part 2 Programming in MATLAB Part 2 A computer program is a sequence of computer commands. In a simple program the commands are executed one after the other in the order they are typed. MATLAB provides several

More information

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics.

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics. Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics. Starting MATLAB - On a PC, double click the MATLAB icon - On a LINUX/UNIX machine, enter the command:

More information

Files and File Management Scripts Logical Operations Conditional Statements

Files and File Management Scripts Logical Operations Conditional Statements Files and File Management Scripts Logical Operations Conditional Statements Files and File Management Matlab provides a group of commands to manage user files pwd: Print working directory displays the

More information

H.C. Chen 1/24/2019. Chapter 4. Branching Statements and Program Design. Programming 1: Logical Operators, Logical Functions, and the IF-block

H.C. Chen 1/24/2019. Chapter 4. Branching Statements and Program Design. Programming 1: Logical Operators, Logical Functions, and the IF-block Chapter 4 Branching Statements and Program Design Programming 1: Logical Operators, Logical Functions, and the IF-block Learning objectives: 1. Write simple program modules to implement single numerical

More information

McTutorial: A MATLAB Tutorial

McTutorial: A MATLAB Tutorial McGill University School of Computer Science Sable Research Group McTutorial: A MATLAB Tutorial Lei Lopez Last updated: August 2014 w w w. s a b l e. m c g i l l. c a Contents 1 MATLAB BASICS 3 1.1 MATLAB

More information

1 Introduction to Matlab

1 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 information

CS 221 Lecture. Tuesday, 13 September 2011

CS 221 Lecture. Tuesday, 13 September 2011 CS 221 Lecture Tuesday, 13 September 2011 Today s Agenda 1. Announcements 2. Boolean Expressions and logic 3. MATLAB Fundamentals 1. Announcements First in-class quiz: Tuesday 4 October Lab quiz: Thursday

More information

Eng Marine Production Management. Introduction to Matlab

Eng Marine Production Management. Introduction to Matlab Eng. 4061 Marine Production Management Introduction to Matlab What is Matlab? Matlab is a commercial "Matrix Laboratory" package which operates as an interactive programming environment. Matlab is available

More information

MATLAB Introductory Course Computer Exercise Session

MATLAB Introductory Course Computer Exercise Session MATLAB Introductory Course Computer Exercise Session This course is a basic introduction for students that did not use MATLAB before. The solutions will not be collected. Work through the course within

More information

1 Overview of the standard Matlab syntax

1 Overview of the standard Matlab syntax 1 Overview of the standard Matlab syntax Matlab is based on computations with matrices. All variables are matrices. Matrices are indexed from 1 (and NOT from 0 as in C!). Avoid using variable names i and

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

Flow Control. CSC215 Lecture

Flow Control. CSC215 Lecture Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements

More information

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 1. Pointers As Kernighan and Ritchie state, a pointer is a variable that contains the address of a variable. They have been

More information

Boolean Logic & Branching Lab Conditional Tests

Boolean Logic & Branching Lab Conditional Tests I. Boolean (Logical) Operations Boolean Logic & Branching Lab Conditional Tests 1. Review of Binary logic Three basic logical operations are commonly used in binary logic: and, or, and not. Table 1 lists

More information

Introduction to GNU-Octave

Introduction 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 information

What is a Function? EF102 - Spring, A&S Lecture 4 Matlab Functions

What 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 information

Programming in MATLAB

Programming 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 information

ECE 202 LAB 3 ADVANCED MATLAB

ECE 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 information

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB 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

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment What is MATLAB? MATLAB PROGRAMMING Stands for MATrix LABoratory A software built around vectors and matrices A great tool for numerical computation of mathematical problems, such as Calculus Has powerful

More information

Conditional Statement

Conditional Statement Conditional Statement 1 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition Also called Branching How do we specify conditions?

More information

SECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing

SECTION 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 information

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

More information

The Arithmetic Operators

The Arithmetic Operators The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

More information

5. Selection: If and Switch Controls

5. Selection: If and Switch Controls Computer Science I CS 135 5. Selection: If and Switch Controls René Doursat Department of Computer Science & Engineering University of Nevada, Reno Fall 2005 Computer Science I CS 135 0. Course Presentation

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical

More information

MATLAB Project: Getting Started with MATLAB

MATLAB Project: Getting Started with MATLAB Name Purpose: To learn to create matrices and use various MATLAB commands for reference later MATLAB built-in functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos,

More information

Introduction to MATLAB

Introduction 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 information

Page 1 of 7 E7 Spring 2009 Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering. Practice Midterm 01

Page 1 of 7 E7 Spring 2009 Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering. Practice Midterm 01 Page 1 of E Spring Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Practice Midterm 1 minutes pts Question Points Grade 1 4 3 6 4 16 6 1 Total Notes (a) Write your name and your SID on the top right

More information

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

How 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 information

Digital Image Processing

Digital 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 information

Introduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018)

Introduction 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 information

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives CS 61A Scheme Spring 2018 Discussion 7: March 21, 2018 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme

More information

An Introduction to MATLAB

An Introduction to MATLAB An Introduction to MATLAB Day 1 Simon Mitchell Simon.Mitchell@ucla.edu High%level%language% Programing%language%and%development%environment% Built4in%development%tools% Numerical%manipulation% Plotting%of%functions%and%data%

More information

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

CSE/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 information

Quick MATLAB Syntax Guide

Quick MATLAB Syntax Guide Quick MATLAB Syntax Guide Some useful things, not everything if-statement Structure: if (a = = = ~=

More information