MATLAB Introductory Course Computer Exercise Session

Size: px
Start display at page:

Download "MATLAB Introductory Course Computer Exercise Session"

Transcription

1 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 the session. Make sure you understand what you are doing and what the commands are doing. Collect your questions and ask for help. If you are already familiar with Matlab, this will finish quickly. After you have gone through this MATLAB introduction, start with the assignment exercises. If MATLAB should for some reasons not available, OCTAVE, a free MATLAB clone, is a good alternative. A documentation is given at The syntax is quite similar to MATLAB and most of the exercises given here apply without changes. QTOCTAVE even provides a nice user interface that is similar to the MATLAB window. OC- TAVE is mostly MATLAB compatible but there are some differences when it comes to plotting functionality and image handling. In these cases use the documentation. One difference is that the OCTAVE command image automatically scales the data to the full range, while the MATLAB command does not. 1 Welcome to MATLAB This session introduces some important parts of MATLAB but you will not get far without searching more information on your own. Therefore, use the MATLAB help system and other external sources to find out more. To log on to the computers you need a student account and a password. Having logged in, start MATLAB. The default user interface contains three parts: Workspace: Here the variables that you have entered will be listed (none so far). Command History: Recently run commands. Command Window: The most important window. This is where you enter the commands to run MATLAB. 2 The MATLAB help system The MATLAB help system is reached by entering >> helpdesk in the command window. A window containing the MATLAB help will open. The left part of the window contains a navigator to help you browse through the documentation. There are different ways to get help. A thorough introduction to MATLAB is found in Getting started with MATLAB. It contains the topics covered in this course and some additional material. Apart from Getting started..., the help system contains an index of the MATLAB commands, a search function, and demos. The command >> help command prints a short help text on the command command (command should be replaced by the command you would like to know more about). It is a good habit to always use help on new commands you run into. For instance, try it on itself! Another very useful command is doc. Find out what it does. 1

2 3 Matlab as a calculator Other related commands: By entering numerical expressions, MATLAB can be used as a calculator. Try >> 5+3*2-4/7 What (and why?) is the result of >> round(10*ans)/10 Other round off commands include floor and ceil. Find out what they do. What is ans? The up and down arrows of the keyboard can be used to navigate the command history. You may also enter the first letter(s) of a command that you have already entered. The arrow keys will then browse through all entered commands that start with these letters. Exponential functions can be entered by using. To use the base e there is a special command, exp. The natural logarithm is computed with log. The imaginary unit is denoted i or j. Some commands that are relevant to complex numbers are imag, real, abs, and angle. Display format Normally, MATLAB displays floating point numbers with 4 decimals. If you would like to see more decimals, you can use >> format long To switch back, use format short. If you do not want to see the result of a command, add a semicolon at the of the expression. Elementary functions Compute cos(π/3) = sin(π/4) In some cases, one has to take into account that MATLAB has a limited numerical precision. What should be the result of >> sin(pi) Variables For more complex computations, it is often convenient to store intermediate results in variables: >> a=3 >> b=6; >> c=b*a 2

3 Defined variables are visible in the Workspace window. You could also use the command whos. If you use the same variable name again, it gets a new value. For instance, you can write >> a = a+1 To delete variables, there is a command named clear. The risk of making mistakes often decreases if you clear variables when they are no longer needed. For large computations, it is sometimes also necessary, to avoid filling the entire memory. 4 Scripts and documentation Often, you would like to run a sequence of commands several times, perhaps with different values of the variables. This could be done through MATLAB - scripts, or m-files. An m-file is simply a text file with a sequence of MATLAB commands, with the file extension.m (the same extension is also used for functions, which will be studied later). The file name will become a command name that can be used in MATLAB like any other command. To remember what the script does, and thus be able to use it another day, comment your code. Comments start with the sign %. Start MATLAB s editor with the command edit. Write a solution for the following problem in your m-file: David has obtained a loan to buy something nice and expensive. He ints to pay 10% of his salary every month until he has payed his debt. The loan has a rate of interest of 1% per month. Write a script where David can enter the amount of the loan and his salary, and which computes how large his debt is next month. One suggestion for a solution could be: disp('the script computes the new debt after this month.'); debt = 2000; salary = 3000; rate = 0.01; % Rate of interest per month paymentsize = 0.1; % Percentage of salary to pay new_debt = debt + debt*rate - paymentsize*salary; disp('result:'); display(new_debt); Save the script by choosing Save or Save As in the File menu. Name the script myscript.m. The script is saved in the file myscript.m. Now, you can use it just like any other MATLAB command: >> myscript If the script is saved in a certain directory (folder), it might be necessary to change directory in MATLAB to be able to run it. You can also add the folder to the path using addpath or pathtool. The command dir prints the contents of the current directory (where you are), the command cd can be used to change directory, and pwd shows in which directory you are. 5 Matrices The matrix is the basic data type in MATLAB, and there are very powerful built-in functions for matrix manipulations and computations. A vector is a special case of a matrix. Construct some matrices: 3

4 >> A = [1 2 5;3 8 10] >> b = [7; 4; 5] >> c = [3 2 1] What is the function of semicolons here? What do the following commands do? >> b(3)? >> A(2,3)? (What is the meaning of 2 and 3?) >> A(:,2)? (Here : means all rows.) >> A(1,:)? To retrieve elements from a matrix in this way is called indexing. We can perform matrix calculations: >> A*b Why wouldn t A*c work? Use.' to get the matrix transpose. (Using ' gives the conjugate of the transposed matrix.) Try it out on some matrix! There are other ways to create certain special matrices. What do the following commands do: >> H = ones(3,2)? >> B = eye(3)? >> y = 3:9? >> x = 1:4:21? (What is the purpose of the 4 here?) >> z = 10:-0.5:7? A few more examples of indexing what happens here? >> ind = [1 4 5] >> y(ind) >> A(2,2:) Indexing submatrices also works for assignments: >> A = ones(4,4) >> A(1,1) = 9 >> A(2,3) = 4 >> A(3,2:4) = [7 3 9] Construct a larger matrix from the submatrices A and b: >> D = [A [b;20]] The brackets are used here to group a number of submatrices into a new matrix. As before, the semicolon indicates a line break (cf. the figure below). Matrix functions A Most elementary functions work with matrices, too, where they operate componentwise. Operations that have a special meaning in connection with matrices (such as *, /, and ^) can be forced to operate componentwise by adding a point before the operator. Try for instance b 20 4

5 >> x = 0:0.1:1 >> cos(x).^2./x What is the difference between >> A*B and >> A.*B A common application for matrices is to represent systems of linear equations. As is well known, the system Ax = b, where A and b are matrices and x unknown, can be solved by left multiplication of the inverse of A, i.e., x = A 1 b. However, in MATLAB this is not the best way to solve the equation system. More matrix commands The following commands are very useful. Try them out and use the MATLAB help system to understand how they work. Special matrices: zeros, rand, randn, eye, diag. Linear algebra: inv, det, eig, svd, null Processing data: sort, max, min, find, sum. 6 Writing and documenting your own functions Apart from saving scripts in m-files, that could be used to repeatedly invoke a command sequence, it is also possible to write your own functions in MATLAB. A function may take one or several arguments (inputs) and can return one or several return values. Functions always begin with a line of the form >> x = A\b computes the solution in a faster and numerically more reliable way. If A 1 exists, the solution will be the same as above. Otherwise (that is, for over- or underdetermined systems), the system is solved in least-squares sense. Solve the system of equations 5x 1 + 2x 2 = 3 3x 1 + 2x 2 = 5 Solution: function out = filename(in1,in2,in3) out specifies which variable is going to be returned from the function. filename is the name of the function. The function should be saved in a file named filename.m. in1, in2 and in3 are the arguments of the function. A function can have any number of arguments and return values. If two return values are to be given, the function header takes the form function [out1,out2] = filename(in1,in2,in3) Let us rewrite our script (that computed the new debt after the month) as a function: 5

6 function new_debt = loancomp(debt,salary,rate,paymentsize) % new_debt = loancomp(debt,salary,rate,paymentsize) % Computes the debt after this month. % Arguments: debt, salary, rate of interest, and % percentage of salary to pay. new_debt = debt + debt*rate - paymentsize*salary; Write the code in a file named loancomp.m. This file will be used for the next exercise as well. Comparing the function with the corresponding script, we can see that the debt and salary were entered directly in the script. Here we let those be arguments instead, which means that we let the person running the function decide for the values. The function is invoked with >> loancomp(davids_debt,davids_salary,... davids_rate,davids_paymentsize) where davids_debt, davids_salary, davids_rate and davids_paymentsize are numerical values, or variables containing these values. Compute the size of David s debt next month, if the loan is 1000 EUR, David earns 2500 EUR/month, the rate is 0.02, and he pays is 20% of his salary. There are two main differences between functions and scripts: 1. Functions may have arguments and return values. 2. A script shares the variables with the Workspace from where it was invoked. Functions, on the other hand, create their own workspaces, where only the arguments are defined to begin with. New variables can then be defined inside the function. When all commands of the function have been evaluated, the return value is sent to MATLAB s Workspace, and the workspace of the function disappears (together with its variables). Many (but not all) of the built-in functions in MATLAB are written in the same way as in the example above. For instance, to see how the function mean is implemented, write >> type mean 7 Plots What is drawn by the following code? >> t = 0:0.01:6*pi; >> y = cos(t); >> plot(t,y) What is the difference compared to >> plot(y) To plot several functions in the same figure, you can for instance use >> plot(t,y,t,sin(t)) 6

7 Another option is to use the command hold. Find out how it works, and plot cos and sin in the same figure. You can use zoom to magnify parts of the figure (or use the magnifying glass icon in the figure window). Another useful command to specify what to show is axis. axis equal will give the axis the same scale, so a circle will look like a circle. The grid command adds a grid to the figure. Title and axis labels can be added to the figure by using title, xlabel, and ylabel. You can print your figure with the command print. To include a MATLAB plot in a report (or similar) might be very illustrative. The figures can be saved using Save As in the File menu, or by giving extra flags to the print command. Deping on in which context the figure will be used, there are different file formats to choose between. For instance, the jpg format might be suitable for publishing figures on the Internet, while eps is useful for LATEX, and meta for files to be included in Word (only in Windows). 8 Images MATLAB represents images are represented as matrices. Colour images are three-dimensional matrices. The colour channels are in the third dimension. Use imread to load an image into a variable and look at the structure and data type of this variable in the MATLAB workspace. Do not forget to add a semicolon at the of the load command! Generate a cutout of the image using the indexing commands of Section 5. Use the MATLAB help system to find out how image works and use this command to visualise the cutout. Note that you might have to clip or scale the values appropriately. (Note that the R2008b release of MATLAB seems to have a bug in its imagesc command implementation, resulting in it not scaling the image data as claimed in the documentation.) A histogram can be generated easily with hist. Use imwrite to save the cutout in an image file. You can also save variables in a file. You can do this using the save command. Use load to make the variables available again. The variables are saved in MATLAB s own format (MAT- files), but you can also save them as text. The command >> save min_fil a b c saves the variables a, b and c in a MAT-file. Try it out with the cutout! 9 Control structures Conditions if clauses Often you would like to do different things deping on the value of some variable. In the loan example of Section 6, you might for instance want to check whether the debt is settled. In MATLAB (like in most other programming languages), there is a control structure called if clauses. The following code contains a test, which can be added at the of the loancomp function. It uses an if clause to check if the debt is settled, and in that case set the debt to zero: % Test if the debt is settled: if new_debt <= 0, new_debt = 0; 7

8 disp('the debt is settled!') else disp('the debt is not yet settled.') % Test if the rate of interest is positive: if rate<0 error('the rate of interest must be positive!') Three keywords: if, else and. Following if, we find our condition: new_debt<=0 (<= means less than or equal to). In this example, the condition consists of an inequality, but you could also check whether two variables are equal by ==, or if they are not equal by ~=. If the condition is true, the commands between if and else are executed. Otherwise the commands between else and are executed. In general, we can write if condition commands else commands MATLAB interprets nonzero values as true and 0 as false. Hence, the condition might be an expression that is evaluated to something which is either nonzero or zero. Use help relop or the MATLAB documentation to find the relational operators of MATLAB. The rest of the function is left unchanged. Now test what happens if you enter a negative rate of interest. The command warning can be used to warn about minor issues without interrupting the function. Repetitions As previously mentioned, often one would like to run the same code (at least approximately) a number of times. For this, there are better ways than just repeating the same code over and over again. for loops Suppose that David would like to know his debt, not only in one month, but in, for instance 12 months. Instead of running the function 12 times with different arguments, we can use a for loop. We also introduce a new input argument: number of months. Error handling Sometimes the if clause is used to find an error in the input. In the loan example above we might want to check that the rate of interest is positive. Otherwise we do not want to compute anything, but just print an error message and exit the function. This is obtained with the error command. Add the following test before new_debt is computed: function new_debt = loancomp(debt,salary,rate,... paymentsize,months) % new_debt = loancomp(debt,salary,rate,... % paymentsize,months) % Computes the debt after a number of months. % Arguments: debt, salary, rate of interest, % percentage of salary to pay and 8

9 % number of months. % Test if the rate of interest is positive: if rate<0 error('the rate of interest must be positive!') % Compute the new debt: for t = 1:months debt = debt + debt*rate - paymentsize*salary; new_debt = debt; % Test if the debt is settled: if new_debt <= 0, new_debt = 0; disp('the debt is settled!') else disp('the debt is not yet settled.') The keywords for and enclose the repetitive structure. The variable t will, step by step, take the values given after the = sign, and for each value, the lines between for and are executed. We recognize the colon notation, :, from Section 5. The first time the for loop is run, t will be 1, the second time t will be 2 etc., until t has reached the value of months (e.g. 12). Every time, debt gets a new value. Try removing the semicolon after the computation to see the debts for each month. In the example above, t is only used to keep track of the number of iterations, but it can also be used inside the loop. For instance, let us make debt a vector, where debt(t) gives the debt for month t. Before the for loop, add debt = [debt; zeros(months,1)]; to create a vector where we can save the size of the debt month by month. The line inside the for loop is replaced by debt(t+1) = debt(t) + debt(t)*rate - paymentsize*salary; Otherwise, the function is left as it is. Try this version of the function, and plot a figure of how the debt changes over the months. If you skip the semicolon in the loop, you can also see how the values of debt are entered one by one. Printouts like that may be useful when looking for bugs in the code. while You do not always know in advances how many times to repeat a computation. For instance, David might want to find out after how many months the debt will be settled. For this, one can use a while loop. while checks if a condition is satisfied (in the same way as if) and executes a number of commands if it is. Then the condition is checked again, and the whole procedure is repeated until the condition is not satisfied anymore. We can modify our example to compute at which month the debt is settled using while: function finalmonth = loancomp(debt,salary,rate,paymentsize) % finalmonth = loancomp(debt,salary,rate,paymentsize) % Computes at which month the debt is settled % Arguments: debt, salary, rate of interest, and % percentage of salary to pay % Test if the rate of interest is positive: if rate<0 9

10 error('the rate of interest must be positive!') month_no = 1; while debt(month_no)>0 % Compute the new debt: debt(month_no+1) = debt(month_no) +... debt(month_no)*rate - paymentsize*salary; month_no = month_no+1; finalmonth = month_no; When using a while loop, it is important to make sure that the condition is not always satisfied. In that case, the function would get stuck in an infinite loop 1. This should be checked before entering the loop. In our example, the loop will be infinite if the debt does not decrease every month. We can check this just like we test if the rate of interest is positive. Give a condition which ensures that the loop will be finite (and the debt will be settled): Modify the code so that we do not risk an infinite loop. Apart from the condition above, we could also allow a maximum number of iterations, i.e., we can require that month_no does not exceed 200 (for instance). The upper limit could also be an argument of the function. 1 If this would occur, you can stop the execution by pressing Ctrl-c. 10

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

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

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

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

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB 1 Introduction to MATLAB A Tutorial for the Course Computational Intelligence http://www.igi.tugraz.at/lehre/ci Stefan Häusler Institute for Theoretical Computer Science Inffeldgasse

More information

Matlab and Octave: Quick Introduction and Examples 1 Basics

Matlab and Octave: Quick Introduction and Examples 1 Basics Matlab and Octave: Quick Introduction and Examples 1 Basics 1.1 Syntax and m-files There is a shell where commands can be written in. All commands must either be built-in commands, functions, names of

More information

Grace days can not be used for this assignment

Grace days can not be used for this assignment CS513 Spring 19 Prof. Ron Matlab Assignment #0 Prepared by Narfi Stefansson Due January 30, 2019 Grace days can not be used for this assignment The Matlab assignments are not intended to be complete tutorials,

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

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 functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos, sin,

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

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window. EE 350L: Signals and Transforms Lab Spring 2007 Lab #1 - Introduction to MATLAB Lab Handout Matlab Software: Matlab will be the analytical tool used in the signals lab. The laboratory has network licenses

More information

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group Introduction to MATLAB Simon O Keefe Non-Standard Computation Group sok@cs.york.ac.uk Content n An introduction to MATLAB n The MATLAB interfaces n Variables, vectors and matrices n Using operators n Using

More information

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano MATLAB Lesson I Chiara Lelli Politecnico di Milano October 2, 2012 MATLAB MATLAB (MATrix LABoratory) is an interactive software system for: scientific computing statistical analysis vector and matrix computations

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

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c.

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c. MATLAB BASICS Starting Matlab < PC: Desktop icon or Start menu item < UNIX: Enter matlab at operating system prompt < Others: Might need to execute from a menu somewhere Entering Matlab commands < Matlab

More information

University of Alberta

University of Alberta A Brief Introduction to MATLAB University of Alberta M.G. Lipsett 2008 MATLAB is an interactive program for numerical computation and data visualization, used extensively by engineers for analysis of systems.

More 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

LECTURE 1. What Is Matlab? Matlab Windows. Help

LECTURE 1. What Is Matlab? Matlab Windows. Help LECTURE 1 What Is Matlab? Matlab ("MATrix LABoratory") is a software package (and accompanying programming language) that simplifies many operations in numerical methods, matrix manipulation/linear algebra,

More information

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise

More 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

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

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

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

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

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

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS 1 6 3 Matlab 3.1 Fundamentals Matlab. The name Matlab stands for matrix laboratory. Main principle. Matlab works with rectangular

More information

Computer Project: Getting Started with MATLAB

Computer Project: Getting Started with MATLAB Computer Project: Getting Started with MATLAB Name Purpose: To learn to create matrices and use various MATLAB commands. Examples here can be useful for reference later. MATLAB functions: [ ] : ; + - *

More information

MAT 275 Laboratory 1 Introduction to MATLAB

MAT 275 Laboratory 1 Introduction to MATLAB MATLAB sessions: Laboratory 1 1 MAT 275 Laboratory 1 Introduction to MATLAB MATLAB is a computer software commonly used in both education and industry to solve a wide range of problems. This Laboratory

More information

Lecture 2: Variables, Vectors and Matrices in MATLAB

Lecture 2: Variables, Vectors and Matrices in MATLAB Lecture 2: Variables, Vectors and Matrices in MATLAB Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1 and Chapter 2. Variables

More information

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li MATLAB Tutorial Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li 1 Table of Contents Section 1: Accessing MATLAB using RamCloud server...3 Section 2: MATLAB GUI Basics. 6 Section 3: MATLAB

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

Lecturer: Keyvan Dehmamy

Lecturer: Keyvan Dehmamy MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications

More information

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming using familiar mathematical notation The name Matlab stands

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

Short Version of Matlab Manual

Short Version of Matlab Manual Short Version of Matlab Manual This is an extract from the manual which was used in MA10126 in first year. Its purpose is to refamiliarise you with the matlab programming concepts. 1 Starting MATLAB 1.1.1.

More information

The value of f(t) at t = 0 is the first element of the vector and is obtained by

The value of f(t) at t = 0 is the first element of the vector and is obtained by MATLAB Tutorial This tutorial will give an overview of MATLAB commands and functions that you will need in ECE 366. 1. Getting Started: Your first job is to make a directory to save your work in. Unix

More information

Getting To Know Matlab

Getting To Know Matlab Getting To Know Matlab The following worksheets will introduce Matlab to the new user. Please, be sure you really know each step of the lab you performed, even if you are asking a friend who has a better

More information

General Information. There are certain MATLAB features you should be aware of before you begin working with MATLAB.

General Information. There are certain MATLAB features you should be aware of before you begin working with MATLAB. Introduction to MATLAB 1 General Information Once you initiate the MATLAB software, you will see the MATLAB logo appear and then the MATLAB prompt >>. The prompt >> indicates that MATLAB is awaiting a

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

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP) Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

More information

2.0 MATLAB Fundamentals

2.0 MATLAB Fundamentals 2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,

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

MATLAB/Octave Tutorial

MATLAB/Octave Tutorial University of Illinois at Urbana-Champaign Department of Electrical and Computer Engineering ECE 298JA Fall 2017 MATLAB/Octave Tutorial 1 Overview The goal of this tutorial is to help you get familiar

More information

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA MATLAB (short for MATrix LABoratory) is a very useful piece of software for numerical

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

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

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY What is MATLAB? MATLAB (MATrix LABoratory) developed by The Mathworks, Inc. (http://www.mathworks.com) Key Features: High-level language for numerical

More information

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen. University of Illinois at Urbana-Champaign Department of Electrical and Computer Engineering ECE 298JA Fall 2015 Matlab Tutorial 1 Overview The goal of this tutorial is to help you get familiar with MATLAB

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

Getting started with MATLAB

Getting started with MATLAB Getting started with MATLAB You can work through this tutorial in the computer classes over the first 2 weeks, or in your own time. The Farber and Goldfarb computer classrooms have working Matlab, but

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Contents 1.1 Objectives... 1 1.2 Lab Requirement... 1 1.3 Background of MATLAB... 1 1.4 The MATLAB System... 1 1.5 Start of MATLAB... 3 1.6 Working Modes of MATLAB... 4 1.7 Basic

More information

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia The goal for this tutorial is to make sure that you understand a few key concepts related to programming, and that you know the basics

More information

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D) MATLAB(motivation) Why use MATLAB? Mathematcal computations Used a lot for problem solving Statistical Analysis (e.g., mean, min) Visualisation (1D-3D) Signal processing (Fourier transform, etc.) Image

More information

To start using Matlab, you only need be concerned with the command window for now.

To start using Matlab, you only need be concerned with the command window for now. Getting Started Current folder window Atop the current folder window, you can see the address field which tells you where you are currently located. In programming, think of it as your current directory,

More information

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr A0B17MTB Matlab Part #1 Miloslav Čapek miloslav.capek@fel.cvut.cz Filip Kozák, Viktor Adler, Pavel Valtr Department of Electromagnetic Field B2-626, Prague You will learn Scalars, vectors, matrices (class

More information

Learning from Data Introduction to Matlab

Learning from Data Introduction to Matlab Learning from Data Introduction to Matlab Amos Storkey, David Barber and Chris Williams a.storkey@ed.ac.uk Course page : http://www.anc.ed.ac.uk/ amos/lfd/ This is a modified version of a text written

More information

Teaching Manual Math 2131

Teaching Manual Math 2131 Math 2131 Linear Algebra Labs with MATLAB Math 2131 Linear algebra with Matlab Teaching Manual Math 2131 Contents Week 1 3 1 MATLAB Course Introduction 5 1.1 The MATLAB user interface...........................

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

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks MATLAB Basics Stanley Liang, PhD York University Configure a MATLAB Package Get a MATLAB Student License on Matworks Visit MathWorks at https://www.mathworks.com/ It is recommended signing up with a student

More information

MATLAB The first steps. Edited by Péter Vass

MATLAB The first steps. Edited by Péter Vass MATLAB The first steps Edited by Péter Vass MATLAB The name MATLAB is derived from the expression MATrix LABoratory. It is used for the identification of a software and a programming language. As a software,

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

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

LAB 1 General MATLAB Information 1

LAB 1 General MATLAB Information 1 LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by

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

DSP First. Laboratory Exercise #1. Introduction to MATLAB

DSP First. Laboratory Exercise #1. Introduction to MATLAB DSP First Laboratory Exercise #1 Introduction to MATLAB The Warm-up section of each lab should be completed during a supervised lab session and the laboratory instructor should verify the appropriate steps

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing

More information

Matlab Introduction. Scalar Variables and Arithmetic Operators

Matlab Introduction. Scalar Variables and Arithmetic Operators Matlab Introduction Matlab is both a powerful computational environment and a programming language that easily handles matrix and complex arithmetic. It is a large software package that has many advanced

More information

AMS 27L LAB #2 Winter 2009

AMS 27L LAB #2 Winter 2009 AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles

More information

Programming in Mathematics. Mili I. Shah

Programming in Mathematics. Mili I. Shah Programming in Mathematics Mili I. Shah Starting Matlab Go to http://www.loyola.edu/moresoftware/ and login with your Loyola name and password... Matlab has eight main windows: Command Window Figure Window

More information

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013 Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1 Where is Matlab? Find the Matlab under the folder 1.

More information

Octave Tutorial Machine Learning WS 12/13 Umer Khan Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany

Octave Tutorial Machine Learning WS 12/13 Umer Khan Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany Octave Tutorial Machine Learning WS 12/13 Umer Khan Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany 1 Basic Commands Try Elementary arithmetic operations: 5+6, 3-2,

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

Computational Modelling 102 (Scientific Programming) Tutorials

Computational Modelling 102 (Scientific Programming) Tutorials COMO 102 : Scientific Programming, Tutorials 2003 1 Computational Modelling 102 (Scientific Programming) Tutorials Dr J. D. Enlow Last modified August 18, 2003. Contents Tutorial 1 : Introduction 3 Tutorial

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB MATLAB stands for MATrix LABoratory. Originally written by Cleve Moler for college linear algebra courses, MATLAB has evolved into the premier software for linear algebra computations

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

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text Chapter 1 Getting Started How to Get Matlab Matlab physically resides on each of the computers in the Olin Hall labs. See your instructor if you need an account on these machines. If you are going to go

More information

The Very Basics of the R Interpreter

The Very Basics of the R Interpreter Chapter 2 The Very Basics of the R Interpreter OK, the computer is fired up. We have R installed. It is time to get started. 1. Start R by double-clicking on the R desktop icon. 2. Alternatively, open

More information

CITS2401 Computer Analysis & Visualisation

CITS2401 Computer Analysis & Visualisation FACULTY OF ENGINEERING, COMPUTING AND MATHEMATICS CITS2401 Computer Analysis & Visualisation SCHOOL OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING Topic 3 Introduction to Matlab Material from MATLAB for

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

Matlab Tutorial, CDS

Matlab Tutorial, CDS 29 September 2006 Arrays Built-in variables Outline Operations Linear algebra Polynomials Scripts and data management Help: command window Elisa (see Franco next slide), Matlab Tutorial, i.e. >> CDS110-101

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

PART 1 PROGRAMMING WITH MATHLAB

PART 1 PROGRAMMING WITH MATHLAB PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment

More information

MATLAB BEGINNER S GUIDE

MATLAB BEGINNER S GUIDE MATLAB BEGINNER S GUIDE About MATLAB MATLAB is an interactive software which has been used recently in various areas of engineering and scientific applications. It is not a computer language in the normal

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

How to learn MATLAB? Some predefined variables

How to learn MATLAB? Some predefined variables ECE-S352 Lab 1 MATLAB Tutorial How to learn MATLAB? 1. MATLAB comes with good tutorial and detailed documents. a) Select MATLAB help from the MATLAB Help menu to open the help window. Follow MATLAB s Getting

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

A very brief Matlab introduction

A very brief Matlab introduction A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading

More 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

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras Module No. #01 Lecture No. #1.1 Introduction to MATLAB programming

More information

MATLAB: Quick Start Econ 837

MATLAB: Quick Start Econ 837 MATLAB: Quick Start Econ 837 Introduction MATLAB is a commercial Matrix Laboratory package which operates as an interactive programming environment. It is a programming language and a computing environment

More information

Lab 1 Intro to MATLAB and FreeMat

Lab 1 Intro to MATLAB and FreeMat Lab 1 Intro to MATLAB and FreeMat Objectives concepts 1. Variables, vectors, and arrays 2. Plotting data 3. Script files skills 1. Use MATLAB to solve homework problems 2. Plot lab data and mathematical

More information

Introduction to MATLAB Programming

Introduction to MATLAB Programming Introduction to MATLAB Programming Arun A. Balakrishnan Asst. Professor Dept. of AE&I, RSET Overview 1 Overview 2 Introduction 3 Getting Started 4 Basics of Programming Overview 1 Overview 2 Introduction

More information

STAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006

STAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006 STAT 39 Handout Making Plots with Matlab Mar 26, 26 c Marina Meilă & Lei Xu mmp@cs.washington.edu This is intended to help you mainly with the graphics in the homework. Matlab is a matrix oriented mathematics

More information

Introduction to MATLAB programming: Fundamentals

Introduction to MATLAB programming: Fundamentals Introduction to MATLAB programming: Fundamentals Shan He School for Computational Science University of Birmingham Module 06-23836: Computational Modelling with MATLAB Outline Outline of Topics Why MATLAB?

More information

Introduction to MATLAB Practical 1

Introduction to MATLAB Practical 1 Introduction to MATLAB Practical 1 Daniel Carrera November 2016 1 Introduction I believe that the best way to learn Matlab is hands on, and I tried to design this practical that way. I assume no prior

More information

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System CHAPTER 1 INTRODUCTION Digital signal processing (DSP) technology has expanded at a rapid rate to include such diverse applications as CDs, DVDs, MP3 players, ipods, digital cameras, digital light processing

More information

MATLAB BASICS. M Files. Objectives

MATLAB BASICS. M Files. Objectives Objectives MATLAB BASICS 1. What is MATLAB and why has it been selected to be the tool of choice for DIP? 2. What programming environment does MATLAB offer? 3. What are M-files? 4. What is the difference

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

General MATLAB Information 1

General MATLAB Information 1 Introduction to MATLAB General MATLAB Information 1 Once you initiate the MATLAB software, you will see the MATLAB logo appear and then the MATLAB prompt >>. The prompt >> indicates that MATLAB is awaiting

More information

An Introduction to MATLAB See Chapter 1 of Gilat

An Introduction to MATLAB See Chapter 1 of Gilat 1 An Introduction to MATLAB See Chapter 1 of Gilat Kipp Martin University of Chicago Booth School of Business January 25, 2012 Outline The MATLAB IDE MATLAB is an acronym for Matrix Laboratory. It was

More information