ECE 202 LAB 3 ADVANCED MATLAB

Size: px
Start display at page:

Download "ECE 202 LAB 3 ADVANCED MATLAB"

Transcription

1 Version 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 access to MATLAB and the signal processing toolbox MATERIALS Formatted ¼ floppy diskette (optional) Speakers Speaker Control Box OBJECTIVES After completing this lab you should be more familiar with MATLAB. Specifically, you should be able to write your own MATLAB scripts and functions and know how to use some of the functions provided in the signal processing toolbox. INTRODUCTION MATLAB has many tools to assist in the development of signal and systems. These tools include functions that allow you to listen to signals and save signals as audio files. There are also many tools that allow you to display see signals in many different forms. MATLAB also has tools to help design and test analog and digital filters. PRELAB Throughout this lab you will be asked to create many plots and images. By now, you should be familiar with how to title and label plots in MATLAB. You must label and title all plots and images turned in with your lab worksheet, even if you are not specifically told to do so. Answer Questions 1 2.

2 Version of 13 PROGRAMMING THE MATLAB EDITOR MATLAB provides its own text editor that can be used to create and edit script files. To open the MATLAB editor, use the EDIT command at the command prompt. The editor may also be opened form the menu toolbar by selecting File New M-file. MATLAB script files are saved with the extension.m. SCRIPT FILES As you become more familiar with MATLAB, you will find it helpful to store lengthy sequences of commands in a single file that can be edited and run multiple times. These files are called MATLAB scripts. They are ASCII text documents that contain MATLAB commands. The commands are typed in the file exactly as they would be typed at the command prompt and are executed in the order that they appear from top to bottom. All of the general commands are supported and MATLAB has commands and structures designed specifically for use in script files. Script File Template As with other programming languages, you should always document your source code with comments. Comments are ignored by the programming language compiler (or interpreter) and are denoted in MATLAB with the percent sign (%). Script files that you turn in with your lab reports need to contain a heading that documents your name, the lab number, the lab title, and the date that the work was completed. Following the heading should be a few comment lines that describe what tasks the script file performs. After the heading and program description, the variables that are to be used in the script file are declared and commented. Large scripts should be broken up into sections. Each section should contain comments describing what actions are being performed. These comments will assist you during debugging and will help others understand your script. Any variables declared in the script file stay resident in memory after the script file has executed. The variables in script files are global, which means they may be accessed outside of the script file. Scripting Commands MATLAB provides many commands and structures that may be used in script files. FOR Loop The FOR loop is used to run through a block of code a specific number of times. The syntax for the FOR loop is:

3 Version of 13 for counter = start:stop statements to be executed where counter is any legal variable name start specifies the starting value, usually an integer stop specifies the ing value, usually an integer indicates the of the for block All lines of code between the FOR and END commands are indented. Though this indentation is not required, it is recommed because it improves readability and makes debugging easier. The first time through the loop, the variable counter is assigned the value of start. At the of the executable statements, counter is incremented by one. This process is repeated until counter is less than or equal to stop. For example, to the code for a FOR loop to iterate ten times would be for count = 1:10 By default, MATLAB increments the loop counter by 1 each time through the loop. To change the default increment, the FOR command uses the syntax for count = start:incr:stop where incr is the new increment The command for count = 1:.5:10 increments count by.5, thereby causing 20 iterations of the loop. WHILE Loop The WHILE loop is similar to the FOR loop in that it is used to repeatedly execute a block of code. The WHILE loop differs in that it uses a conditional statement to exit the loop. The syntax for a WHILE loop is while <condition is true> statements to be executed As long as the condition is true, the program will remain in the loop. The condition is usually a comparison with a relational operator. Some examples are: x > 0 y <= z (a > 0) & (a < 20)

4 Version of 13 Another difference in the WHILE loop is that the conditional value must be edited within the loop statements. Given the following code: while x < 10 y = [y x + 3]; x = x + 0.1; the program will continue to loop until x is no longer less than 10. In this example, the last time the program loops is when x = 9.9. When x = 10, x is no longer less than 10 (x < 10 is false) and the loop is exited. If the line x = x was omitted, x would remain equal to its original value of 1. Since 1 is always less than 10 the loop would never be exited. This is called an infinite loop. BREAK The break command terminates the execution of FOR and WHILE loops. IF, ELSEIF, and ELSE The IF statement is used to execute a segment of code only if specified conditions are true. The syntax for the IF statement is: if <condition is true> statements to execute If the condition is true, the code immediately following the IF statements is executed. If the condition is false, the code is skipped. The ELSE statement is used in conjunction with the IF statement to execute a block of code if the condition equates to false. The syntax for the IF ELSE statement is: if <condition is true> execute this statement else execute this statement For example, consider the function f(x) = x + 1 for x 0 1 for x < 0 To determine the value of f(x) you would use the following IF ELSE statements: if x >= 0 y = x + 1 else y = 1

5 Version of 13 In the cases where there are three or more choices, the ELSEIF statement may be used in conjunction with the IF ELSE statements. The syntax for the IF ELSEIF ELSE structure is: if <condition> statements elseif <condition> statements else statements The statements after the ELSEIF command are executed only if its condition is true and if all previous IF and ELSEIF conditions are false. EXAMPLE SCRIPT FILE The following is a script file that prompts the user for an integer and determines if the integer is a prime number. % John Smith % ECE 202 Lab 3 % Advanced MATLAB % 23 June 2000 % % This script file determines if a number entered by the user is a prime number. % The number is first tested to see if it is greater than one. By definition, one % is neither a prime number nor a composite number. If the number is greater than one % it is tested to see if it is equal to two. Two is the first prime number (and the % only even prime number). If the number is not two, the number is divided by all the % numbers between two and the square root of the number. If the number is not equally % divisible by all the numbers between two and its square root then the number is prime. % % Variables % % number Number to test % flag Set to 1 if number is prime, 0 if number is not prime % sqr_root Square root approximation of number % count Used as variable in FOR loop % Prompt user for number to test number = input('enter number to test for prime: '); % Test to see if number is less than or equal to 1 if number <= 1 flag = 0; % Set flag to 0 elseif number == 2 % Test to see if number is equal to 2 flag = 1; % Set flag to 1 else % Test to see if number is prime flag = 1; % Assume number is prime. Value will be change if test fails. % Calculate the square root of number and round down to nearest integer.

6 Version of 13 sqr_root = fix(sqrt(number)); % Loop to divide number by all numbers between 2 and the square root of number for count = 2:sqr_root if rem(number,count) == 0 % Test remainder value for number divided by count. % If remainder equals 0, then number is not prime. flag = 0; % Set flag to 0 break; % Break out of FOR loop ; % End of nested IF block ; % End of FOR loop ; % End of IF ELSEIF ELSE block % Display results deping of value of FLAG if flag == 1 fprintf('\n%i is prime.\n',number) else fprintf('\n%i is not prime.\n',number) ; Answer Question 3. Notice that a percent sign (%) was used for all of the descriptive information given at the beginning of the file. If you type help prime at a MATLAB prompt, it will return all of the comments at the beginning of the file until a line is encountered that does not begin with the comment character, %. FUNCTIONS Functions are like script files that can take arguments and return values. The first line of a function, or the declaration line, must contain the keyword FUNCTION. The syntax for FUNCTION is: function r = function_name(x) where r is the value returned by the function function_name is the name of the function x is the input argument A function that is going to return two or more values needs to have the output variables enclosed in square brackets ([]). function [mag, phase] = complex_num(x) A function with more than one input argument must list all of the arguments within parenthesis, seperated by a comma: function v = volumn(x,y,z) The lines following the function delcaration line should be comments describing the function. These are the lines that are displayed when the user types help function_name at the command

7 Version of 13 prompt. The HELP command will display all the comment lines, starting with the line after the declaration line, until a non-comment line is encountered. The variables used in functions are local only to that function. Unlike variables declared in script files, variables declared in functions are only accessible by the function and are not kept in memory after the function has terminated. EXAMPLE FUNCTION FILE The following is a function that determines the heavside (unit step) values. function signal = heavside(time) % This function creates a vector signal that is the same length as vector time. % The values of the signal are zero when the values of time are negative. % The values of signal are one when the values of time are positive. % This is equivalent to the unit step. signal = zeros(size(time)); % Create signal with all zeros non_zero = find(time > 0); % Find elements of time greater than zero % Assign one to the elements of signal that correspond to the elements % of time that are positive. signal(non_zero) = ones(size(non_zero)); Answer Question 4. COMPLEX NUMBERS MATLAB stores and displays complex numbers in the same way you would find them in a text book. To enter the complex number 3 + 4i you would enter» 3 + 4i MATLAB also allows the use of j instead of i to represent complex numbers.» 3 + 4j Complex numbers may also be entered as» 1 + i*2» 7 + j*1 Complex numbers can also be assigned to variables, vectors and matrixes.» x = 2 +i;

8 Version of 13» y = [5 + 3j, 5-3j];» Z = [3 + 3j, 3-3j;1 + 2j, 1-2j]; It is a good practice not to use i or j as variable names, especially if you are using complex numbers. Answer Questions 5 7. PLOTTING MATLAB has many tools that allow you to plot data in different ways. You should already be familiar with the MATLAB PLOT command. Here you will be introduced to other methods for plotting data. THE SUBPLOT COMMAND MATLAB enables you to add multiple plots to a figure window with the SUBPLOT command. The syntax for SUBPLOT is subplot(m,n,p) where m is the number of rows n is the number of columns p is the pth window, counted from left to right and top to bottom. For example, to create a figure with four plots, two across and two down, the command would be subplot(2,2,1) To plot data in the lower left plot, the commands would be subplot(2,2,3) plot(data) LOGARITHMIC PLOTS MATLAB has three commands that allow data to be plot on a variety of logarithmic plots: SEMILOGX, SEMILOGY, and LOGLOG. The commands take the same arguments as the PLOT command, but differ in the following ways: SEMILOGX uses a logarithmic scale for the abscissa (x-axis). SEMILOGY uses a logarithmic scale for the ordinate (y-axis). LOGLOG uses logarithmic scales for both the abscissa and the ordinate.

9 Version of 13 THE GRID COMMAND The GRID command turns the gridlines of the selected plot on and off. To turn the grid on you would use the command grid on To turn the grid off grid off The GRID command by itself can be used to toggle the grid on and off. THE LEGEND COMMAND The leg command puts a leg on the current plot. The simplest form of the command is leg( string_1, string_2, ) where the strings specify the labels for the curves on the plot. To place the leg in a specified location the syntax would be leg(,n) where N is an integer value from -1 to 4, which places the leg in the following locations: -1 To the right of the plot 0 Automatic placement of least conflict with data. 1 Upper-right corner. 2 Upper-left corner. 3 Lower-left corner. 4 Lower-right corner. The leg may also be moved by dragging it to the desired location. A label in the leg can be edited by double clicking on it. To remove the leg from the plot the syntax would be leg off Answer Questions THE STEM COMMAND The STEM command plots the individual data points with perpicular lines, or stems, connecting the data point to the abscissa. The syntax for the STEM command is stem(x,y) stem(x,y, filled )

10 Version of 13 stem(x,y, string ) The first option s each stem with an open circle, and the second option s each stem with a filled circle. The third option has a string as a third argument. The values in the string determine the line type, symbol and color. Refer to the PLOT command for more information on valid line types. THE BAR COMMAND The BAR command plots the data as a bar graph. The syntax for the BAR command is bar(x,y) bar(x,y, string ) The argument string is a single character that determines the color of the bar graph. Refer to the PLOT command for information on valid color values. THE STAIRS COMMAND The STAIRS command creates a stair step plot. The syntax for the stair command is the same as for the BAR command. Answer Questions CHANGING PLOT PROPERTIES You should already be familiar with MATLAB s GET and SET commands. These commands can be used to change the property values of plots. The properties of plots may also be changed by using the tools available from the Tools menu in the figure window. With these tools you can change the properties of the axes, lines and text that appear in the figure. The tools are enabled from the Tools menu by selecting Enable Plot Editing. EDITING THE AXES PROPERTIES To edit the axes properties, first click on the axes of the plot, then from the Tools menu, select Axes Properties. The Edit Axes Properties dialog box will open, as displayed in Figure 1. From this dialog box, you may enter a title, labels, change the axis scale to linear or logarithmic, change the limits of the axes, change the number of tick marks, and turn on or off the grid lines for a given axis.

11 Version of 13 EDITING LINE PROPERTIES Figure 1. Edit Axes Properties Dialog Box. To edit the line properties, first click on the line (curve) to edit, then from the Tools menu, select Line Properties. The Edit line Properties dialog box will open, as displayed in Figure 2. You can change the line width, style and color, and the marker size and symbol. Figure 2. Edit Line Properties Dialog Box.

12 Version of 13 EDITING TEXT PROPERTIES To edit the properties of any text in the figure, click on the text you want to change, then from the Tools menu, select Text Properties. The Edit Font Properties dialog box will open, as displayed in Figure 3. You can change the font, style and size of any text just as you would in any Windows program. Answer Questions AUDIO TOOLS Figure 3. Edit Font Properties Dialog Box. MATLAB comes with a set of audio tools that allow you to listen to, save, record, and load signals and Microsoft WAV (.wav) sound files. THE SOUND COMMAND The SOUND command plays a vector as a sound. Signals can be represent as vectors, such as the declaration» t = 0:0.001:5;» y = sin(100 * pi * t); The syntax for the SOUND command is sound(y) sound(y,fs) sound(y,fs,bits)

13 Version of 13 where y is the vector representing the signal Fs is the sampling frequency (the number of elements of vector y played per second) bits is the bits per sample If Fs is omitted, as in the first option, SOUND uses a sampling frequency of 8192 Hz. THE SOUNCSC COMMAND The SOUNDSC command is the same as the SOUND command except that the data is scaled so that the sound is played as load as possible without clipping. Answer Questions

Introduction to MATLAB LAB 1

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

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

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

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab

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

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

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

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB 1 INTRODUCTION TO MATLAB PLOTTING WITH MATLAB Plotting with MATLAB x-y plot Plotting with MATLAB MATLAB contains many powerful functions for easily creating plots of several different types. Command plot(x,y)

More information

Introduction to MATLAB

Introduction to MATLAB 58:110 Computer-Aided Engineering Spring 2005 Introduction to MATLAB Department of Mechanical and industrial engineering January 2005 Topics Introduction Running MATLAB and MATLAB Environment Getting help

More information

A Guide to Using Some Basic MATLAB Functions

A Guide to Using Some Basic MATLAB Functions A Guide to Using Some Basic MATLAB Functions UNC Charlotte Robert W. Cox This document provides a brief overview of some of the essential MATLAB functionality. More thorough descriptions are available

More information

8. Control statements

8. Control statements 8. Control statements A simple C++ statement is each of the individual instructions of a program, like the variable declarations and expressions seen in previous sections. They always end with a semicolon

More information

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER BENC 2113 DENC ECADD 2532 ECADD LAB SESSION 6/7 LAB

More information

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Prof. Manoochehr Shirzaei. RaTlab.asu.edu RaTlab.asu.edu Introduction To MATLAB Introduction To MATLAB This lecture is an introduction of the basic MATLAB commands. We learn; Functions Procedures for naming and saving the user generated files

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

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX 1) Objective The objective of this lab is to review how to access Matlab, Simulink, and the Communications Toolbox, and to become familiar

More information

LESSON 3. In this lesson you will learn about the conditional and looping constructs that allow you to control the flow of a PHP script.

LESSON 3. In this lesson you will learn about the conditional and looping constructs that allow you to control the flow of a PHP script. LESSON 3 Flow Control In this lesson you will learn about the conditional and looping constructs that allow you to control the flow of a PHP script. In this chapter we ll look at two types of flow control:

More information

Dr. Iyad Jafar. Adapted from the publisher slides

Dr. Iyad Jafar. Adapted from the publisher slides Computer Applications Lab Lab 6 Plotting Chapter 5 Sections 1,2,3,8 Dr. Iyad Jafar Adapted from the publisher slides Outline xy Plotting Functions Subplots Special Plot Types Three-Dimensional Plotting

More information

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

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

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

What is Matlab? A software environment for interactive numerical computations

What is Matlab? A software environment for interactive numerical computations What is Matlab? A software environment for interactive numerical computations Examples: Matrix computations and linear algebra Solving nonlinear equations Numerical solution of differential equations Mathematical

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

Introduction to MATLAB

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

Laboratory 1 Octave Tutorial

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

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

MATLAB Guide to Fibonacci Numbers

MATLAB Guide to Fibonacci Numbers MATLAB Guide to Fibonacci Numbers and the Golden Ratio A Simplified Approach Peter I. Kattan Petra Books www.petrabooks.com Peter I. Kattan, PhD Correspondence about this book may be sent to the author

More information

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029 Programming Basics and Practice GEDB029 Decision Making, Branching and Looping Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029 Decision Making and Branching C language possesses such decision-making capabilities

More information

Table of Contents. Introduction.*.. 7. Part /: Getting Started With MATLAB 5. Chapter 1: Introducing MATLAB and Its Many Uses 7

Table of Contents. Introduction.*.. 7. Part /: Getting Started With MATLAB 5. Chapter 1: Introducing MATLAB and Its Many Uses 7 MATLAB Table of Contents Introduction.*.. 7 About This Book 1 Foolish Assumptions 2 Icons Used in This Book 3 Beyond the Book 3 Where to Go from Here 4 Part /: Getting Started With MATLAB 5 Chapter 1:

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

Basic Plotting. All plotting commands have similar interface: Most commonly used plotting commands include the following.

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

MATLAB Introduction to MATLAB Programming

MATLAB Introduction to MATLAB Programming MATLAB Introduction to MATLAB Programming MATLAB Scripts So far we have typed all the commands in the Command Window which were executed when we hit Enter. Although every MATLAB command can be executed

More information

ENGR 1181 MATLAB 09: For Loops 2

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

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Introduction: MATLAB is a powerful high level scripting language that is optimized for mathematical analysis, simulation, and visualization. You can interactively solve problems

More information

EE3TP4: Signals and Systems Lab 1: Introduction to Matlab Tim Davidson Ext Objective. Report. Introduction to Matlab

EE3TP4: Signals and Systems Lab 1: Introduction to Matlab Tim Davidson Ext Objective. Report. Introduction to Matlab EE3TP4: Signals and Systems Lab 1: Introduction to Matlab Tim Davidson Ext. 27352 davidson@mcmaster.ca Objective To help you familiarize yourselves with Matlab as a computation and visualization tool in

More information

MATLIP: MATLAB-Like Language for Image Processing

MATLIP: MATLAB-Like Language for Image Processing COMS W4115: Programming Languages and Translators MATLIP: MATLAB-Like Language for Image Processing Language Reference Manual Pin-Chin Huang (ph2249@columbia.edu) Shariar Zaber Kazi (szk2103@columbia.edu)

More information

Practical 4: The Integrate & Fire neuron

Practical 4: The Integrate & Fire neuron Practical 4: The Integrate & Fire neuron 2014 version by Mark van Rossum 2018 version by Matthias Hennig and Theoklitos Amvrosiadis 16th October 2018 1 Introduction to MATLAB basics You can start MATLAB

More information

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva All copyrights reserved - KV NAD, Aluva Dinesh Kumar Ram PGT(CS) KV NAD Aluva Overview Looping Introduction While loops Syntax Examples Points to Observe Infinite Loops Examples using while loops do..

More information

Additional Plot Types and Plot Formatting

Additional Plot Types and Plot Formatting Additional Plot Types and Plot Formatting The xy plot is the most commonly used plot type in MAT- LAB Engineers frequently plot either a measured or calculated dependent variable, say y, versus an independent

More information

Introduction to Matlab

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

AN INTRODUCTION TO MATLAB

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

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

EE 301 Signals & Systems I MATLAB Tutorial with Questions

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

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MatLab. Introduction to MatLab K. Craig 1 Introduction to MatLab Introduction to MatLab K. Craig 1 MatLab Introduction MatLab and the MatLab Environment Numerical Calculations Basic Plotting and Graphics Matrix Computations and Solving Equations

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

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

Introduction to MATLAB

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

INTRODUCTION TO MATLAB

INTRODUCTION TO MATLAB 1 of 18 BEFORE YOU BEGIN PREREQUISITE LABS None EXPECTED KNOWLEDGE Algebra and fundamentals of linear algebra. EQUIPMENT None MATERIALS None OBJECTIVES INTRODUCTION TO MATLAB After completing this lab

More information

lab MS Excel 2010 active cell

lab MS Excel 2010 active cell MS Excel is an example of a spreadsheet, a branch of software meant for performing different kinds of calculations, numeric data analysis and presentation, statistical operations and forecasts. The main

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

Why Is Repetition Needed?

Why Is Repetition Needed? Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable

More information

QUICK INTRODUCTION TO MATLAB PART I

QUICK INTRODUCTION TO MATLAB PART I QUICK INTRODUCTION TO MATLAB PART I Department of Mathematics University of Colorado at Colorado Springs General Remarks This worksheet is designed for use with MATLAB version 6.5 or later. Once you have

More information

Our Strategy for Learning Fortran 90

Our Strategy for Learning Fortran 90 Our Strategy for Learning Fortran 90 We want to consider some computational problems which build in complexity. evaluating an integral solving nonlinear equations vector/matrix operations fitting data

More information

What is MATLAB and howtostart it up?

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

Attia, 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 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 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

Repetition Structures Chapter 9

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

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

More information

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu 0. What is MATLAB? 1 MATLAB stands for matrix laboratory and is one of the most popular software for numerical computation. MATLAB s basic

More information

Finding MATLAB on CAEDM Computers

Finding MATLAB on CAEDM Computers Lab #1: Introduction to MATLAB Due Tuesday 5/7 at noon This guide is intended to help you start, set up and understand the formatting of MATLAB before beginning to code. For a detailed guide to programming

More information

PROGRAMMING WITH MATLAB WEEK 6

PROGRAMMING WITH MATLAB WEEK 6 PROGRAMMING WITH MATLAB WEEK 6 Plot: Syntax: plot(x, y, r.- ) Color Marker Linestyle The line color, marker style and line style can be changed by adding a string argument. to select and delete lines

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

REPETITION CONTROL STRUCTURE LOGO

REPETITION CONTROL STRUCTURE LOGO CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of

More information

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA Starting with a great calculator... Topic 5: Introduction to Programming in Matlab CSSE, UWA! MATLAB is a high level language that allows you to perform calculations on numbers, or arrays of numbers, in

More information

SPARK-PL: Introduction

SPARK-PL: Introduction Alexey Solovyev Abstract All basic elements of SPARK-PL are introduced. Table of Contents 1. Introduction to SPARK-PL... 1 2. Alphabet of SPARK-PL... 3 3. Types and variables... 3 4. SPARK-PL basic commands...

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab This tour introduces the basic notions of programming with Matlab. Contents M-file scripts M-file functions Inline functions Loops Conditionals References M-file scripts A script

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

Computer Programming in MATLAB

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

FDP on Electronic Design Tools - Computing with MATLAB 13/12/2017. A hands-on training session on. Computing with MATLAB

FDP on Electronic Design Tools - Computing with MATLAB 13/12/2017. A hands-on training session on. Computing with MATLAB A hands-on training session on Computing with MATLAB in connection with the FDP on Electronic Design Tools @ GCE Kannur 11 th 15 th December 2017 Resource Person : Dr. A. Ranjith Ram Associate Professor,

More information

EE 1105 Pre-lab 3 MATLAB - the ins and outs

EE 1105 Pre-lab 3 MATLAB - the ins and outs EE 1105 Pre-lab 3 MATLAB - the ins and outs INTRODUCTION MATLAB is a software tool used by engineers for wide variety of day to day tasks. MATLAB is available for UTEP s students via My Desktop. To access

More information

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

Some elements for Matlab programming

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

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB.

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB. MATLAB Introduction This guide is intended to help you start, set up and understand the formatting of MATLAB before beginning to code. For a detailed guide to programming in MATLAB, read the MATLAB Tutorial

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 4 Visualising Data Dr Richard Greenaway 4 Visualising Data 4.1 Simple Data Plotting You should now be familiar with the plot function which is

More information

Language Fundamentals

Language Fundamentals Language Fundamentals VBA Concepts Sept. 2013 CEE 3804 Faculty Language Fundamentals 1. Statements 2. Data Types 3. Variables and Constants 4. Functions 5. Subroutines Data Types 1. Numeric Integer Long

More information

KaleidaGraph Quick Start Guide

KaleidaGraph Quick Start Guide KaleidaGraph Quick Start Guide This document is a hands-on guide that walks you through the use of KaleidaGraph. You will probably want to print this guide and then start your exploration of the product.

More information

Chapter 4 C Program Control

Chapter 4 C Program Control 1 Chapter 4 C Program Control Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 4 C Program Control Outline 4.1 Introduction 4.2 The Essentials of Repetition

More information

Lab 7 (All Sections) Prelab: Introduction to Verilog

Lab 7 (All Sections) Prelab: Introduction to Verilog Lab 7 (All Sections) Prelab: Introduction to Verilog Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work 1 Objective The

More information

ECE Lesson Plan - Class 1 Fall, 2001

ECE Lesson Plan - Class 1 Fall, 2001 ECE 201 - Lesson Plan - Class 1 Fall, 2001 Software Development Philosophy Matrix-based numeric computation - MATrix LABoratory High-level programming language - Programming data type specification not

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

MATLAB SUMMARY FOR MATH2070/2970

MATLAB SUMMARY FOR MATH2070/2970 MATLAB SUMMARY FOR MATH2070/2970 DUNCAN SUTHERLAND 1. Introduction The following is inted as a guide containing all relevant Matlab commands and concepts for MATH2070 and 2970. All code fragments should

More information

MATLAB Second Seminar

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

Nuts & Bolts guide to MATLAB

Nuts & Bolts guide to MATLAB Nuts & Bolts guide to MATLAB Adrian KC Lee ScD MGH-HST Athinoula A. Martinos Center for Biomedical Imaging; Department of Radiology, Harvard Medical School, Boston, MA. November 18 2010 Why.N.How Tutorial

More information

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER BENC 2113 DENC ECADD 2532 ECADD LAB SESSION 6/7 LAB

More information

WINTER 2017 ECE 102 ENGINEERING COMPUTATION STANDARD HOMEWORK #3 ECE DEPARTMENT PORTLAND STATE UNIVERSITY

WINTER 2017 ECE 102 ENGINEERING COMPUTATION STANDARD HOMEWORK #3 ECE DEPARTMENT PORTLAND STATE UNIVERSITY WINTER 2017 ECE 102 ENGINEERING COMPUTATION STANDARD HOMEWORK #3 ECE DEPARTMENT PORTLAND STATE UNIVERSITY ECE 102 Standard Homework #3 (HW-s3) Problem List 15 pts Problem #1 - Curve fitting 15 pts Problem

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

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

Microsoft Excel. Charts

Microsoft Excel. Charts Microsoft Excel Charts Chart Wizard To create a chart in Microsoft Excel, select the data you wish to graph or place yourself with in the conjoining data set and choose Chart from the Insert menu, or click

More information

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing SECTION 1: INTRODUCTION ENGR 112 Introduction to Engineering Computing 2 Course Overview What is Programming? 3 Programming The implementation of algorithms in a particular computer programming language

More information

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

More information

Armstrong Atlantic State University Engineering Studies MATLAB Marina 2D Plotting Primer

Armstrong Atlantic State University Engineering Studies MATLAB Marina 2D Plotting Primer Armstrong Atlantic State University Engineering Studies MATLAB Marina D Plotting Primer Prerequisites The D Plotting Primer assumes knowledge of the MATLAB IDE, MATLAB help, arithmetic operations, built

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

Chapter 3: Rate Laws Excel Tutorial on Fitting logarithmic data

Chapter 3: Rate Laws Excel Tutorial on Fitting logarithmic data Chapter 3: Rate Laws Excel Tutorial on Fitting logarithmic data The following table shows the raw data which you need to fit to an appropriate equation k (s -1 ) T (K) 0.00043 312.5 0.00103 318.47 0.0018

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

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

Chapter 3: Programming with MATLAB

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

GUI Alternatives. Syntax. Description. MATLAB Function Reference plot. 2-D line plot

GUI Alternatives. Syntax. Description. MATLAB Function Reference plot. 2-D line plot MATLAB Function Reference plot 2-D line plot GUI Alternatives Use the Plot Selector to graph selected variables in the Workspace Browser and the Plot Catalog, accessed from the Figure Palette. Directly

More information

The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development

The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Chapter 7 Graphics Learning outcomes Label your plots Create different

More information

3 The L oop Control Structure

3 The L oop Control Structure 3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement

More information