MATLAB Second Seminar

Size: px
Start display at page:

Download "MATLAB Second Seminar"

Transcription

1 MATLAB Second Seminar

2 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 would be nice if you didn't have to manually type these commands at the command prompt whenever you want to use them.

3 Script M-filesM Standard ASCII text files Contain a series of MATLAB expressions A script does not define a new workspace % Comments start start with with "%" "%" character pause pause % Suspend execution - hit hit any any key key to to continue. keyboard % Pause Pause & return control to to command line. line. % Type Type "return" to to continue. break break % Terminate execution of of current loop/file. return % Exit Exit current function % Return to to invoking function/command line. line. Continue % go go to to next next iteration Input Input % Prompt for for user user input input

4 Creating Scripts with MATLAB Editor/Debugger Automatically just saves files as ASCII text files for you. Scripts in MATLAB has the ".m" suffix. They are also called "M-files". Open Matlab Editor: File New M-file OR: >> edit Run

5 A Simple Script Write a program which receives a number from the user, calculates it s square root (use sqrt command) and after the user hits a key, displays the result. save the script as "square_root_script.m" % a simple MATLAB m-file to calculate the % square root of an input numbers. my_num=input('insert a number'); % now calculate the square root of the number and print it out: square_root = sqrt(my_num); disp ('Hit any key to see the result') pause; square_root

6 Running Scripts >> square_root_script The header - comments you place at the beginning of your scripts will be returned to users when they get help for your script. >> help square_root_script Note: The variables defined in the script remain in the workspace even after the script finishes running,

7 Running Scripts (2) Find and Replace ctrl+f Key words Wrong use of key words Indenting: Ctrl+I

8 Flow Control Constructs Logic Control: IF / ELSEIF / ELSE SWITCH / CASE / OTHERWISE Iterative Loops: FOR WHILE

9 The if, elseif and else statements Works on Conditional statements Logic condition is true if its different then 0. if if I == == J A(I,J) = 2; 2; else else if if abs(i-j) == == 1 A(I,J) = -1; -1; else else A(I,J) = 0; 0; end end %else %else if if end end %if %if if if I == == J A(I,J) = 2; 2; elseif abs(i-j) == == 1 A(I,J) = -1; -1; else else A(I,J) = 0; 0; end end ELSEIF does not need a matching END, while ELSE IF does.

10 Switch, Case, and Otherwise More efficient than elseif statements Only the first matching case is executed switch input_num case case -1-1 input_str = 'minus one'; one'; case case 0 input_str = 'zero'; case case 1 input_str = 'plus 'plus one'; one'; case case {-10,10} input_str = '+/- '+/- ten'; ten'; otherwise input_str = 'other value'; end end

11 Problem Build a program which receives a variable x and its units (mm, cm, inch, meter) and calculates Y- it s value in centimeters units. Use switch case. 1 Inch = 2.54 cm Write a comment for error case. Save the file under units.m

12 Solution x = 3.0; 3.0; units units = 'mm'; 'mm'; switch units units case case {'in','inch'} y = 2.54*x; % converts to to centimeters case case {'m','meter'} y = x*100; % converts to to centimeters case case { 'millimeter','mm'} y = x/10; x/10; disp disp ([num2str(x) ' in in ' units units ' converted to to cm cm is is :' :' num2str(y)]) case case {'cm','centimeter'} y = x; x; otherwise disp disp (['unknown units:' units]) y = nan; nan; end end

13 The for loop Similar to other programming languages Repeats loop a set number of times (based on index) Can be nested Each loop is closed with end. N=10; N=10; for for I = 1:2:N 1:2:N for for J = 1:N 1:N A(I,J) = 1/(I+J-1); end end end end

14 The while loop Similar to other programming languages Repeats loop until logical condition returns FALSE. Can be nested. Stopping infinity loop: Ctrl+C Ctrl+break I=1; I=1; N=10; N=10; while while I<=N I<=N J=1; J=1; while while J<=N J<=N A(I,J)=1/(I+J-1); J=J+1; end end I=I+1; end end

15 Problem Write a script that asks for a temperature (in degrees Fahrenheit) computes the equivalent temperature in degrees Celcius. The script should keep running until no number is provided to convert. use isempty C=5*(F-32)/9

16 Solution while while 1 % use use of of an an infinite loop loop TinF TinF = input('temperature in in F: F: '); '); % get get input input if if isempty(tinf) % how how to to get get out out break break end end TinC TinC = 5*(TinF - 32)/9; % conversion disp(' ') ') disp([' ==> ==> Temperature in in C = ',num2str(tinc)]) disp(' ') ') end end

17 Repetition: Animation demo The function movie replays a sequence of captured frames Construct a movie of a 360 tour around the Matlab logo % logomovie make make movie movie of of degree degree logo logo tour tour logo; logo; no_frames=40; dtheta=360/no_frames; for forframe frame = 1:no_frames, camorbit(dtheta,0) M(frame) = getframe(gcf); end end % now now display display captured movie movie movie(gcf,m); logomovie.m

18 Functions Functions describe subprograms Take inputs, generate outputs Have local variables (invisible in global workspace) Core MATLAB (Built-in) Functions sin, abs, exp,... Can t be displayed on screen MATLAB-supplied M-file Functions mean, linspace, Can be displayed on screen User-created M-file Functions

19 Core MATLAB (Built-in) Functions Elementary built-in functions >> help elfun % a list of these functions sin sin % Sine. exp exp % Exponential. abs abs % Absolute value. round % Round towards nearest integer. Special Math functions >> help specfun lcm lcm cart2sph % Least common multiple. % Transform Cartesian to to spherical % coordinates. Special functions - toolboxes Each toolbox has a list of special functions that you can use

20 Structure of a Function M-fileM Keyword: function Function Name (same as file name.m) Output Argument(s) Input Argument(s) Online Help MATLAB Code function y = mean(x) % MEAN MEAN Average or or mean mean value. % For For vectors, MEAN(x) returns the the mean mean value. % For For matrices, MEAN(x) is is a row row vector % containing the the mean mean value value of of each each column. [m,n] [m,n] = size(x); if if m == == 1 m = n; n; end end y = sum(x)/m;»output_value = mean(input_value) Command Line Syntax

21 Multiple Input & Output Arguments function function r = ourrank(x,tol) Multiple Input % OURRANK OURRANK Rank Rank of of a matrix matrix Arguments (, ) s = svd(x); if if (nargin == == 1) 1) Multiple Output tol tol = max(size(x))*s(1)*eps; Arguments [, ] end end r = sum(s sum(s > tol); tol); function function [mean,stdev] = ourstat(x) % OURSTAT OURSTAT Mean Mean & std. std. deviation deviation [m,n] [m,n] = size(x); if if m == == 1 m = n; n; end end mean mean = sum(x)/m; stdev stdev = sqrt(sum(x.^2)/m mean.^2);» RANK = ourrank(rand(5),0.1);» [MEAN,STDEV] = ourstat(1:99);

22 nargin, nargout, nargchk nargin number of input arguments - Many of Matlab functions can be run with different number of input variables. nargout number of output arguments - efficiency nargchk check if number of input arguments is between some low and high values

23 Workspaces in MATLAB MATLAB (or Base) Workspace: For command line and script file variables. Function Workspaces: Each function has its own workspace for local variables. Name of Input/output variables can be either equal or different then the variable name in the calling workspace. Communicate to Function Workspace via inputs & outputs. Global Workspace: Global variables can be shared by multiple workspaces. (Must be initialized in all relevant workspaces.) Initialize global variables in all relevant workspaces:»global variable_name Initialize global variables in the source workspace before referring to them from other workspaces.

24 Tips for using Global Variables DON T USE THEM If you absolutely must use them: Avoid name conflicts >>whos global %shows the contents of the global workspace >>clear global %erases the variable from both local and global workspaces. >>isglobal()

25 MATLAB Calling Priority High variable built-in function subfunction private function MEX-file P-file M-file» cos='this cos='this string.'; string.';» cos(8) cos(8) ans ans = r» clear clear cos cos» cos(8) cos(8) ans ans = Low

26 Add path >> addpath C:\EMEM899\Somedirectory Set path

27 Visual Debugging Select Workspace Set Auto- Breakpoints Set Breakpoint Clear Breaks Step In Single Step Continue Quit Debugging

28 Example: Visual Debugging (2) Editor/Debugger opens the relevant file and identifies the line where the error occurred. Current Location Current Workspace (Function)

29 Example: Visual Debugging (3) Error message Debug Mode Access to Function s Workspace

30 Some Useful MATLAB commands what List all m-files in current directory dir List all files in current directory ls Same as dir type test Display test.m in command window delete test Delete test.m cd a: Change directory to a: chdir a: Same as cd pwd Show current directory which test Display current directory path to test.m why In case you ever needed a reason

31 Problem Write a function that asks for a temperature (in degrees Fahrenheit) computes the equivalent temperature in degrees Celcius. The function should give an error massage in case no number is provided to convert. use nargin.

32 Solution function TinC=temp2(TinF) if if nargin==0 % if if there is is no no input disp('no temparture was was entered'); TinC=nan; else TinC = 5*(TinF - 32)/9; % conversion disp(' ') ') disp([' ==> ==> Temperature in in C =',num2str(tinc)]) disp(' ') ') end end

33 To read files in MATLAB Input if the file is an ascii table, use load if the file is ascii but not a table, file I/O needs fopen and fclose Reading in data from file using fopen depends on type of data (binary or text) Default data type is binary

34 What Is GUIDE? Graphical User Interface Design Environment provides a set of tools for creating graphical user interfaces (GUIs). GUIDE automatically generates an M-file that controls how the GUI operates. Starting GUIDE: >> guide OR: axes Push buttons Static text Pop-up menu

35 GUIDE Tools - The Layout Editor In the Quick Start dialog, select the Blank GUI (Default) template Component panel Layout area Display names of components: File preferences Show names in component palette Lay out your GUI by dragging components (panels, push buttons, pop-up menus, or axes) from the component palette, into the layout area Drag to resize

36 Using the Property Inspector Labeling the Buttons Select Property Inspector from the View menu. Select button by clicking it. Fill the name in the String field. Property Inspector Activate GUI

37 Programming a GUI Callbacks are functions that execute in response to some action by the user. A typical action is clicking a push button. You program the GUI by coding one or more callbacks for each of its components. A GUI's callbacks are found in an M-file that GUIDE generates automatically. Callback template for a push button:

38 handles structure Save the objects handles: handles.objectname Save global data can be used outside the function. Example: popup menu: Value user choice of the popup menu

Introduction to Matlab. Matlab Basics. Ondrej Lexa.

Introduction to Matlab. Matlab Basics. Ondrej Lexa. Matlab Basics Ondrej Lexa lexa@natur.cuni.cz 2 What is Matlab? A software environment for interactive numerical computations Examples: Matrix computations and linear algebra Solving nonlinear equations

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

Lecture 3. Introduction to Matlab

Lecture 3. Introduction to Matlab Lecture 3 Introduction to Matlab Programming Today s Lecture Matlab programming Programming environment and search path M-file scripts and functions Flow control statements Function functions Programming

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

Introduction to Matlab

Introduction to Matlab EL1150, Lecture 2 Matlab Programming Introduction to Matlab Based on lectures by F. Gustafsson, Linköping University http://www.kth.se/ees/utbildning/kurshemsidor/control/el1150 1 Today s Lecture Matlab

More information

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An. CSE 10 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Weichung Wang 2003 NCTS-NSF Workshop on Differential Equations, Surface Theory, and Mathematical Visualization NCTS, Hsinchu, February 13, 2003 DE, ST, MV Workshop Matlab 1 Main

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 4: Programming in Matlab Yasemin Bekiroglu (yaseminb@kth.se) Florian Pokorny(fpokorny@kth.se) Overview Overview Lecture 4: Programming in Matlab Wrap Up More on Scripts and Functions Wrap Up Last

More information

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

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

Chapter 1 Introduction to MATLAB

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

More information

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An. CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

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

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

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

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

A QUICK INTRODUCTION TO MATLAB

A QUICK INTRODUCTION TO MATLAB A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Basic operations and a few illustrations This set is independent from rest of the class notes. Matlab will be covered in recitations and occasionally

More information

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Intro to matlab getting started Basic operations and a few illustrations This set is indepent from rest of the class notes. Matlab will be covered

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

There are two ways to launch Graphical User Interface (GUI). You can either

There are two ways to launch Graphical User Interface (GUI). You can either How to get started? There are two ways to launch Graphical User Interface (GUI). You can either 1. Click on the Guide icon 2. Type guide at the prompt Just follow the instruction below: To start GUI we

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

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

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

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

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

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

ECE 202 LAB 3 ADVANCED MATLAB

ECE 202 LAB 3 ADVANCED MATLAB Version 1.2 1 of 13 BEFORE YOU BEGIN PREREQUISITE LABS ECE 201 Labs EXPECTED KNOWLEDGE ECE 202 LAB 3 ADVANCED MATLAB Understanding of the Laplace transform and transfer functions EQUIPMENT Intel PC with

More information

Finding, Starting and Using Matlab

Finding, Starting and Using Matlab Variables and Arrays Finding, Starting and Using Matlab CSC March 6 &, 9 Array: A collection of data values organized into rows and columns, and known by a single name. arr(,) Row Row Row Row 4 Col Col

More information

INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD. July 2018

INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD. July 2018 INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths July 2018 Outline MATLAB Scripts Relational Operations Program Control Statements Writing

More information

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

What is a Function? EF102 - Spring, A&S Lecture 4 Matlab Functions What is a Function? EF102 - Spring, 2002 A&S Lecture 4 Matlab Functions What is a M-file? Matlab Building Blocks Matlab commands Built-in commands (if, for, ) Built-in functions sin, cos, max, min Matlab

More information

ENGR 253 LAB #1 - MATLAB Introduction

ENGR 253 LAB #1 - MATLAB Introduction ENGR 253 LAB #1 - MATLAB Introduction Objective Understanding and hands on experience with MATLAB with focus on Signal Processing. Resources Signals & Systems textbook by Oppenheim and Willsky Windows

More information

Chapters 6-7. User-Defined Functions

Chapters 6-7. User-Defined Functions Chapters 6-7 User-Defined Functions User-Defined Functions, Iteration, and Debugging Strategies Learning objectives: 1. Write simple program modules to implement single numerical methods and algorithms

More information

Programming 1. Script files. help cd Example:

Programming 1. Script files. help cd Example: Programming Until now we worked with Matlab interactively, executing simple statements line by line, often reentering the same sequences of commands. Alternatively, we can store the Matlab input commands

More 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

Introduction to MATLAB

Introduction to MATLAB to MATLAB Spring 2019 to MATLAB Spring 2019 1 / 39 The Basics What is MATLAB? MATLAB Short for Matrix Laboratory matrix data structures are at the heart of programming in MATLAB We will consider arrays

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

Files and File Management Scripts Logical Operations Conditional Statements

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

More information

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

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

EE 216 Experiment 1. MATLAB Structure and Use

EE 216 Experiment 1. MATLAB Structure and Use EE216:Exp1-1 EE 216 Experiment 1 MATLAB Structure and Use This first laboratory experiment is an introduction to the use of MATLAB. The basic computer-user interfaces, data entry techniques, operations,

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

Outline. User-based knn Algorithm Basics of Matlab Control Structures Scripts and Functions Help

Outline. User-based knn Algorithm Basics of Matlab Control Structures Scripts and Functions Help Outline User-based knn Algorithm Basics of Matlab Control Structures Scripts and Functions Help User-based knn Algorithm Three main steps Weight all users with respect to similarity with the active user.

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 INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services

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

More information

Chapter 4: Programming with MATLAB

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

More information

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to. Starting Matlab Go to MATLAB Laboratory 09/09/10 Lecture Lisa A. Oberbroeckling Loyola University Maryland loberbroeckling@loyola.edu http://ctx.loyola.edu and login with your Loyola name and password...

More information

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

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB SECTION 2: PROGRAMMING WITH MATLAB MAE 4020/5020 Numerical Methods with MATLAB 2 Functions and M Files M Files 3 Script file so called due to.m filename extension Contains a series of MATLAB commands The

More information

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

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

Introduction to MATLAB Introduction to MATLAB Violeta Ivanova, Ph.D. Office for Educational Innovation & Technology violeta@mit.edu http://web.mit.edu/violeta/www Topics MATLAB Interface and Basics Calculus, Linear Algebra,

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

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

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

More information

Linear Algebra and MATLAB

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

More information

CM0340 Tutorial 2: More MATLAB

CM0340 Tutorial 2: More MATLAB CM0340 Tutorial 2: More MATLAB Last tutorial focussed on MATLAB Matrices (Arrays) and vectors which are fundamental to how MATLAB operates in its key application areas including Multimedia data processing

More information

MATLAB GUIDE UMD PHYS401 SPRING 2011

MATLAB GUIDE UMD PHYS401 SPRING 2011 MATLAB GUIDE UMD PHYS401 SPRING 2011 Note that it is sometimes useful to add comments to your commands. You can do this with % : >> data=[3 5 9 6] %here is my comment data = 3 5 9 6 At any time you can

More 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

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

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

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

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

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

Image Processing Matlab tutorial 2 MATLAB PROGRAMMING

Image Processing Matlab tutorial 2 MATLAB PROGRAMMING School of Engineering and Physical Sciences Electrical Electronic and Computer Engineering Image Processing Matlab tutorial 2 MATLAB PROGRAMMING 1. Objectives: Last week, we introduced you to the basic

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB The language of technical computing AM 581 Computational Laboratory Department of Applied Mechanics, IIT Madras MATLAB: technical computing language & interactive environment for

More information

Lecture 1: Hello, MATLAB!

Lecture 1: Hello, MATLAB! Lecture 1: Hello, MATLAB! Math 98, Spring 2018 Math 98, Spring 2018 Lecture 1: Hello, MATLAB! 1 / 21 Syllabus Instructor: Eric Hallman Class Website: https://math.berkeley.edu/~ehallman/98-fa18/ Login:!cmfmath98

More information

Matlab Tutorial: Basics

Matlab Tutorial: Basics Matlab Tutorial: Basics Topics: opening matlab m-files general syntax plotting function files loops GETTING HELP Matlab is a program which allows you to manipulate, analyze and visualize data. MATLAB allows

More information

! The MATLAB language

! The MATLAB language E2.5 Signals & Systems Introduction to MATLAB! MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to -use environment. Typical

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

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

Quick MATLAB Syntax Guide

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

More information

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

MATLAB Project: Getting Started with MATLAB

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

More information

Introduction to MATLAB. 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

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

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 Introduction To Engineering for ECE Topics Covered: 1. Creating Script Files (.m files) 2. Using the Real Time Debugger

MATLAB Introduction To Engineering for ECE Topics Covered: 1. Creating Script Files (.m files) 2. Using the Real Time Debugger 25.108 Introduction To Engineering for ECE Topics Covered: 1. Creating Script Files (.m files) 2. Using the Real Time Debugger SCRIPT FILE 77-78 A script file is a sequence of MATLAB commands, called a

More information

MATLAB 1. Jeff Freymueller September 24, 2009

MATLAB 1. Jeff Freymueller September 24, 2009 MATLAB 1 Jeff Freymueller September 24, 2009 MATLAB IDE MATLAB Edi?ng Window We don t need no steenkin GUI You can also use MATLAB without the fancy user interface, just a command window. Why? You can

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 GNU-Octave

Introduction to GNU-Octave Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016

More information

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline MATLAB Tutorial EE351M DSP Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Kitaek Bae Outline Part I: Introduction and Overview Part II: Matrix manipulations and common functions Part III: Plots

More 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

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

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: The Basics. Dmitry Adamskiy 9 November 2011

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011 MATLAB: The Basics Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 9 November 2011 1 Starting Up MATLAB Windows users: Start up MATLAB by double clicking on the MATLAB icon. Unix/Linux users: Start up by typing

More 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

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

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

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3. MATLAB Introduction Accessing Matlab... Matlab Interface... The Basics... 2 Variable Definition and Statement Suppression... 2 Keyboard Shortcuts... More Common Functions... 4 Vectors and Matrices... 4

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

Mathworks (company that releases Matlab ) documentation website is:

Mathworks (company that releases Matlab ) documentation website is: 1 Getting Started The Mathematics Behind Biological Invasions Introduction to Matlab in UNIX Christina Cobbold and Tomas de Camino Beck as modified for UNIX by Fred Adler Logging in: This is what you do

More information

Chapter 2. MATLAB Basis

Chapter 2. MATLAB Basis Chapter MATLAB Basis Learning Objectives:. Write simple program modules to implement single numerical methods and algorithms. Use variables, operators, and control structures to implement simple sequential

More information

User Defined Functions

User Defined Functions User Defined Functions 120 90 1 0.8 60 Chapter 6 150 0.6 0.4 30 0.2 180 0 210 330 240 270 300 Objectives Create and use MATLAB functions with both single and multiple inputs and outputs Learn how to store

More information

4.0 Programming with MATLAB

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

More information

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

MATLAB Tutorial. Covered by: Toby Heyn University of Wisconsin, Madison

MATLAB Tutorial. Covered by: Toby Heyn University of Wisconsin, Madison MATLAB Tutorial Covered by: Toby Heyn University of Wisconsin, Madison Before getting started Acknowledgement: Almost entirely, this tutorial compiled from bits of information gathered from various internet

More information

The Mathcad Workspace 7

The Mathcad Workspace 7 For information on system requirements and how to install Mathcad on your computer, refer to Chapter 1, Welcome to Mathcad. When you start Mathcad, you ll see a window like that shown in Figure 2-1. By

More information

MATLAB Lecture 1. Introduction to MATLAB

MATLAB Lecture 1. Introduction to MATLAB MATLAB Lecture 1. Introduction to MATLAB 1.1 The MATLAB environment MATLAB is a software program that allows you to compute interactively with matrices. If you want to know for instance the product of

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

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB? Appendix A Introduction to MATLAB A.1 What Is MATLAB? MATLAB is a technical computing environment developed by The Math- Works, Inc. for computation and data visualization. It is both an interactive system

More information

MATLAB Functions and Graphics

MATLAB Functions and Graphics Functions and Graphics We continue our brief overview of by looking at some other areas: Functions: built-in and user defined Using M-files to store and execute statements and functions A brief overview

More 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