Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 11/03/2003.

Slides:



Advertisements
Similar presentations
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Advertisements

Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
Lecture 14 User-defined functions Function: concept, syntax, and examples © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
M AT L AB Programming: scripts & functions. Scripts It is possible to achieve a lot simply by executing one command at a time on the command line (even.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/20/2003.
Chapter Chapter 4. Think back to any very difficult quantitative problem that you had to solve in some science class How long did it take? How many times.
IT151: Introduction to Programming
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/27/2003.
MATLAB Loops and Branching.
Computer Science in Practice This course is an introduction to problems (and solutions) that arise in applied fields of computer science such as machine.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/27/2003.
Lecture tjwc - 17-Jun-15ISE1/EE2 Computing - Matlab Matlab Lecture 2: More MATLAB Programming u MATLAB has five flow control constructs:  if statements.
Computer Science in Practice This course is an introduction to problems (and solutions) that arise in applied fields of computer science such as machine.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Programming in MATLAB Week 14 – 4/28/09 Kate Musgrave
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/29/2003.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
M ATLAB Tutorial Course 1. Contents Continued  Desktop tools  matrices  Logical &Mathematical operations  Handle Graphics  Ordinary Differential.
General Computer Science for Engineers CISC 106 Lecture 07 James Atlas Computer and Information Sciences 06/29/2009.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
How to think through your program [ principles of good program design ] Rachel Denison MATLAB for Cognitive Neuroscience ICN, 13 December 2007.
Matlab Programming, part 1 M-files It is generally more convenient to program in Matlab using m-files, ascii text files containing a set of Matlab commands.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Creating your first C++ program
CPS120 Introduction to Computer Science Iteration (Looping)
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
Synthesis ENGR 1181 MATLAB 11. Topics  No new material  Covers topics that will be on the Midterm 2 Exam MATLAB 01 – Program Design MATLAB 02 – Introduction.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Scientific Computing Introduction to Matlab Programming.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
MATLAB Programming COMM2M Harry R. Erwin, PhD University of Sunderland.
Matlab tutorial course Lesson 4: Writing your own functions: programming constructs
CPS120 Introduction to Computer Science Iteration (Looping)
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Digital Image Processing Introduction to M-function Programming.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/20/2003.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
MA/CS 375 Fall 2003 Lecture 3. .* Multiplication We can use the.* operator to perform multiplication entry by entry of two matrices:
General Computer Science for Engineers CISC 106 Lecture 15 Dr. John Cavazos Computer and Information Sciences 03/16/2009.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
1 Introduction to Matlab. 2 What is Matlab? Matlab is basically a high level language which has many specialized toolboxes for making things easier for.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
L – Modeling and Simulating Social Systems with MATLAB
L – Modeling and Simulating Social Systems with MATLAB
Functions CIS 40 – Introduction to Programming in Python
Scripts & Functions Scripts and functions are contained in .m-files
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
Introduction to MATLAB
MATLAB Tutorial Dr. David W. Graham.
محاسبات عددی در مهندسی پزشکی جلسه اول و دوم مقدمه ای بر نرم افزار MATLAB گلناز بغدادی 1391.
Creating your first C program
Introduction to MATLAB
Introduction to MATLAB
Introduction to MATLAB
Introduction to MATLAB
Introduction to MATLAB
Matlab Basics Tutorial
Presentation transcript:

Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 11/03/2003

Overview for 11/03/2003 Brief review of topics covered in last session (10/30/2003) Some more plotting Low-level file i/o and handles The profiler and tictoc Some ui commands

Review for 10/30/2003 MATLAB Functions Looping! Optimization

MATLAB Functions Functions are similar to scripts Functions may take arguments Functions may return one or more values

MATLAB Functions, con’t: 2 function [output] = function_name(input_arguments) The above is a function header and should be the first non-comment line in the function file Comments may be placed above the function header

MATLAB Functions, con’t: 3 Example function function [output] = square(input) output = input*input; Body of functions can contain code just like scripts could

Looping! Scripts and functions also allow the ability to loop using conventional for and while loops. Note that the interpreter also lets you do it, it is simply less easy to grasp

For Loops Common to other programming languages for variable = expression statement... statement end

For Loops, con’t: 2 Example: (taken from MATLAB help) a = zeros(k,k) % Preallocate matrix for m = 1:k for n = 1:k a(m,n) = 1/(m+n -1); end

For Loops, con’t: 3 The looping variable is defined in much the same way that we defined arrays/vectors. Ex. m = 1:k Or m = 1:10

For Loops, con’t: 4 Loops are shown to end by the keyword “end” Curly braces are not present to subdivide packets of code Make use of adequate white-space and tabbing to improve code readability

While Loops Similar to while loops in other languages while expression statement … end

While Loops, con’t: 2 Ex. (taken from help while) while (1+eps) > 1 eps = eps/2; end

While Loops, con’t: 3 Same notes apply to while loops. Code is separated by the keyword “end”

Case statements Syntax –switch switch_expr case case_expr statement,...,statement case … {case_expr1,case_expr2,case_expr3,...} statement,...,statement... otherwise statement,...,statement end

Case statements, con’t: 2 Ex. (taken from help case) method = 'Bilinear'; switch lower(method) case {'linear','bilinear'} disp('Method is linear') case 'cubic' disp('Method is cubic') case 'nearest' disp('Method is nearest') otherwise disp('Unknown method.') end Method is linear NOTE – when case matches it will not execute all following cases. (Break not necessary).

MATLAB Code Optimization Two ways to optimize MATLAB code Vectorize code Preallocate matrices Information contained here: p1/help/techdoc/matlab_prog/ch10_p47.shtml

More plotting Plotyy Plot3 Bar3 Surf

Low level File I/O Notes – must open a file and obtain a handle before the commands are used Reading accomplished with fgetl or fgets Writing accomplished with fprintf Exercise

The MATLAB Profiler Keyword profile Aids optimization and debug efforts To turn it on, type profile on To turn it off, type profile off Generating a report is accomplished by typing profile report

Tic and Toc Tic and Toc are built in timing mechanisms for code Less information than a profile report will generate Start the timer by typing tic End the timer and return the elapsed time by typing toc

UI Commands UIGetFile UIPutFile

UIGetFile Allows someone to pick up a file with relatively little effort Will return the filename and directory

UIGetFile, con’t: 2 Syntax –uigetfile uigetfile('FilterSpec‘) –uigetfile('FilterSpec','DialogTitle') –uigetfile('FilterSpec','DialogTitle',x,y) –[FileName,PathName] = uigetfile(...)

UIGetFile, con’t: 3 Ex. [filename, pathname] = uigetfile(... {'*.m;*.fig;*.mat;*.mdl','MATLAB Files … (*.m,*.fig,*.mat,*.mdl)'; '*.m', 'M-files (*.m)';... '*.fig','Figures (*.fig)';... '*.mat','MAT-files (*.mat)';... '*.mdl','Models (*.mdl)';... '*.*', 'All Files (*.*)'},... 'Pick a file');

UIPutFile Similar syntax to UIGetFile uiputfile uiputfile('FilterSpec') uiputfile('FilterSpec','DialogTitle') uiputfile('FilterSpec','DialogTitle',x,y) [FileName,PathName] = uiputfile(...) [FileName,PathName,FilterIndex] = … uiputfile(...)