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

Similar documents
Matlab Programming Introduction 1 2

Programming in Mathematics. Mili I. Shah

Introduction to Engineering gii

Introduction to MATLAB

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

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

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. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

EGR 111 Introduction to MATLAB

Chapter 1 Introduction to MATLAB

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

LAB 1 General MATLAB Information 1

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

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

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

Introduction to MATLAB

Introduction to MatLab. Introduction to MatLab K. Craig 1

PART 1 PROGRAMMING WITH MATHLAB

A Guide to Using Some Basic MATLAB Functions

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

Welcome to EGR 106 Foundations of Engineering II

General MATLAB Information 1

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

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

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

1 Introduction to Matlab

Introduction to Matlab

Finding, Starting and Using Matlab

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

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.

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

A Brief Introduction to MATLAB

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

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial

AMS 27L LAB #1 Winter 2009

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

Computer Programming ECIV 2303 Chapter 1 Starting with MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering

2.0 MATLAB Fundamentals

Using the fprintf command to save output to a file.

AMS 27L LAB #2 Winter 2009

EP375 Computational Physics

Computer Programming in MATLAB

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

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional.

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

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

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

ME 121 MATLAB Lesson 01 Introduction to MATLAB

MATLAB Introduction To Engineering for ECE Topics Covered: 1. Creating Script Files (.m files) 2. Using the Real Time Debugger

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017

Chapter 1: An Overview of MATLAB

Lab 1 Intro to MATLAB and FreeMat

Digital Image Analysis and Processing CPE

Matrix Manipula;on with MatLab

INTRODUCTION TO MATLAB

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

MATLAB TUTORIAL WORKSHEET

Basic MATLAB Tutorial

1. Register an account on: using your Oxford address

University of Alberta

A QUICK INTRODUCTION TO MATLAB

Mathworks (company that releases Matlab ) documentation website is:

Programming in MATLAB

MATLAB The first steps. Edited by Péter Vass

Dr Richard Greenaway

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

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

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

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

A GUIDE FOR USING MATLAB IN COMPUTER SCIENCE AND COMPUTER ENGINEERING TABLE OF CONTENTS

A = [1, 6; 78, 9] Note: everything is case-sensitive, so a and A are different. One enters the above matrix as

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

Introduction to MATLAB

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

McTutorial: A MATLAB Tutorial

Introduction to MATLAB for Engineers, Third Edition

Introduction to MATLAB

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

Course Layout. Go to follow instr. Accessible within campus (only for the first download)

VARIABLES Storing numbers:

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

Computational Modelling 102 (Scientific Programming) Tutorials

Introduction to MATLAB

Introduction to MATLAB

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

MATLAB - Lecture # 4

Introduction to MATLAB 7 for Engineers

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Introduction to MATLAB

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

Lecture 1: Hello, MATLAB!

INTRODUCTION TO NUMERICAL ANALYSIS

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

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Class #15: Experiment Introduction to Matlab

Consider this m file that creates a file that you can load data into called rain.txt

A very brief Matlab introduction

Transcription:

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... Find MATLAB within the Academic Applications folder Matlab has eight main windows: **Command Window Main window, enter variables, runs programs **Command History Window Logs commands entered in the Command Window **Workspace Window Provides information about the variables that are used **Current Directory Window Shows the files in the current directory Figure Window Contains output from graphic commands Editor Window Creates and debugs script and function files Help Window Provides help information Launch Pad Window Provides access to tools, demos, and documentation ** On main screen by default L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 1 / 1 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 2 / 1 Drives/Directories Command Window G drive My Documents (is your G-drive!) H drive: H:\Apps\MatlabFiles\loberbro\ma302 Your own drive is C$ found under My Computer. My Computer is also where you can find a drive associated with your flash-drive. PAY ATTENTION TO THE Current Directory! To type a command the cursor must be placed next to the command prompt (>>). Press Enter for the command to be executed. Multiple commands can be typed by typing a comma (,) between them. A semicolon (;) at the end of a command suppresses the screen output. Upper and lower case characters are not equivalent; i.e., MATLAB is CASE SENSITIVE The up and down arrow keys can be used to scroll through previous commands. Also an old command can be recalled by typing the first few characters followed by the up arrow. L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 3 / 1 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 4 / 1

Good commands Built-In Functions clc Clears the command window of all previous commands and output clear Clears all defined variables in memory CAREFUL WITH THIS COMMAND! You can also clear certain variablenames by typing clear varname1 varname2 who Lists current variables clf Clears the current figure (plot) help topic Displays the help for topic. For example, help clf format sends the output display back to the default format (if you had used the command format type to put output into formatting type) disp( text ) Displays text as output exit or quit to quit Matlab OR use the MENU option under File >> sqrt(4) 2 >> pi 3.1416 sqrt(x) Square root exp(x) Exponential (e x ) abs(x) Absolute value log(x) Natural logarithm sin(x) Sine of x cos(x) Cosine of x tan(x) Tangent of x cot(x) Cotangent of x pi π L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 5 / 1 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 6 / 1 Math Operations Defining Scalar Variables Variable = Numerical value or computable expression Uses typical symbols Dot operations: useful/necessary for use with vectors and matrices NUMERICALLY computes: cos 1 ( 3/2) L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 7 / 1 = is the assignment operator which assigns a value to a variable Left-hand side can include only one variable name Right-hand side can be a number or an expression made up of numbers and/or variables previously assigned numerical values Variables must begin with a letter Press Enter to make the assignment ans is the value of the last expression that is not assigned Be careful with variable names. For example, don t name a variable help Remember: Use semicolon (;) to suppress screen output Multiple commands can be typed by typing a comma (,) between them. L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 8 / 1

Defining Scalar Variables Example: Assign the number 3 to variable a and 4 to variable b. Print out a 2 + b 2 and assign the solution to the variable c. >> a=3; b=4; c = sqrt(a 2+b 2) c = 5 Example: Verify cos 2 x tan x + sin x = 2 2 tan x by calculating each side of the equation for π/5. >> pi/5; >> LHS = cos(x/2) 2, RHS = (tan(x)+sin(x))/(2*tan(x)) LHS = 0.9045 RHS = 0.9045 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 9 / 1 Used to store and manipulate numbers Arranged in rows or columns One-Dimensional Array (Vector) Represents point in n-dimensional space Ex: (x, y) in 2D and (x, y, z) in 3D Row Vector (Use space or comma between numbers) >> [1 2 3] 1 2 3 Column Vector (Use semicolon between numbers) >> [1; 2; 3] 1 2 3 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 10 / 1 Constant Spaced Vectors: From m to n, incremented by q variable = [m : q : n] >> [1:2:7] 1 3 5 7 From m to n with q elements variable = linspace(m,n,q) linspace stands for linearly spaced If no q is given, will give you 100 elements >> linspace(0,1,5) 0 0.2500 0.5000 0.7500 1.0000 Two-Dimensional Array (Matrix) Can store information like a table Solve systems of equations such as 2x + 3y + z = 4 x 5y + 3z = 3 4x 2y + 3z = 2 variable = [1st row; 2nd row;... ; last row] >> [ 2 3 1; 1-5 3; 4-2 3] 2 3 1 1 5 3 4 2 3 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 11 / 1 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 12 / 1

Addressing Elements Vector: ve(k) picks the kth element of ve ve(m:n) picks the mth through nth elements of ve >> [1 5 2 6 8 7] 1 5 2 6 8 7 >> ve(5) 8 >> ve(2:4) 5 2 6 Addressing Elements Matrix: A(m,n) picks the (m, n)th element of the matrix A A(m:n,p:q) picks the (m : n) (p : q) submatrix of the matrix A >> A = [; ;; 2 5 1 8] A = 2 5 1 8 >> A(2,3) 9 >> A(2:4, 1:3) 3 6 9 1 4 9 2 5 1 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 13 / 1 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 14 / 1 Adding Elements Can add elements by using the variable within vector/matrix Must be of appropriate size >> [; ;] >> [B; 2 5 1 8] 2 5 1 8 Deleting Elements Delete elements by assigning nothing to these elements >> [1 5 2 6 8 7] 1 5 2 6 8 7 >> ve(2:4) = [ ] 1 8 7 >> [; ;] >> B(2:3,:) = [ ] L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 15 / 1 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 16 / 1

Helpful Commands for Strings length(a) size(a) reshape(a,m,n) Returns number of elements in the vector A Returns size of matrix A Rearranges A to have m rows and n columns (arranged column-wise) Is an array of characters Created by typing characters within single quotes Can include letters, digits, symbols and spaces >> a = Matlab is AWESOME a = Matlab is AWESOME >> a(1) = M >> a(1:6) Matlab >> a(1:6) = Dr. O. a = Dr. O. is AWESOME L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 17 / 1 L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 18 / 1 Script Files When you run the file, MATLAB executes each line as if you typed it into the command window Very useful; you can edit it, save it, execute it many times and tweak it to experiment with commands they are ASCII files with extention.m; also called m-files MATLAB editor many ways to run an m-file of name filename.m CURRENT DIRECTORY MUST BE RIGHT! 1 type filename in the command window 2 type run filename in the command window 3 type run( filename ) in the command window 4 Within the editor window, press F5 5 Within the editor window, on the Debug menu, chose run... To avoid extraneous output to the command window, put ; after var assignments comment lines begin with % L. Oberbroeckling (Loyola University) MATLAB 09/09/10 Lecture 19 / 1