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

Similar documents
Desktop Command window

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Lecturer: Keyvan Dehmamy

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

Lecture 2 Introduction to MATLAB. Dr.Tony Cahill

Introduction to MATLAB

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

An Introduction to MATLAB II

A very brief Matlab introduction

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

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

Introduction to MATLAB

16.06/16.07 Matlab/Simulink Tutorial

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

1 Introduction to Matlab

A Brief Introduction to MATLAB

Programming in Mathematics. Mili I. Shah

MATLAB Functions and Graphics

AMS 27L LAB #2 Winter 2009

Introduction to MATLAB

Laboratory 1 Octave Tutorial

MATLAB Introductory Course Computer Exercise Session

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Getting started with MATLAB

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

AN INTRODUCTION TO MATLAB

2.0 MATLAB Fundamentals

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

Getting To Know Matlab

Introduction to Matlab

Introduction to MATLAB LAB 1

CM0340 Tutorial 2: More MATLAB

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. 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.

Introduction to MATLAB

Some elements for Matlab programming

Introduction to MATLAB

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

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

Computer Project: Getting Started with MATLAB

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

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

MATLAB Project: Getting Started with MATLAB

Stokes Modelling Workshop

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

MATLAB TUTORIAL WORKSHEET

MATLAB Project: Getting Started with MATLAB

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

A Guide to Using Some Basic MATLAB Functions

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

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

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

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.

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

MATLAB GUIDE UMD PHYS375 FALL 2010

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

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

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

Files and File Management Scripts Logical Operations Conditional Statements

Introduction to MATLAB

What is MATLAB and howtostart it up?

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

MATLAB Introduction to MATLAB Programming

1-- Pre-Lab The Pre-Lab this first week is short and straightforward. Make sure that you read through the information below prior to coming to lab.

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

PART 1 PROGRAMMING WITH MATHLAB

Matlab Introduction. Scalar Variables and Arithmetic Operators

Introduction to MATLAB

MATLAB Premier. Middle East Technical University Department of Mechanical Engineering ME 304 1/50

Introduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018)

Introduction to Matlab

Finding, Starting and Using Matlab

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

Introduction to MatLab. Introduction to MatLab K. Craig 1

Mathworks (company that releases Matlab ) documentation website is:

Digital Image Analysis and Processing CPE

Finding MATLAB on CAEDM Computers

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Matlab Tutorial and Exercises for COMP61021

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

Introduction to Matlab

Matlab Tutorial for COMP24111 (includes exercise 1)

Introduction to Matlab. High-Level Computer Vision Summer Semester 2015

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

ECE Lesson Plan - Class 1 Fall, 2001

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

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

McTutorial: A MATLAB Tutorial

Introduction to Matlab

Grace days can not be used for this assignment

Numerical Methods Lecture 1

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

MATLAB GUIDE UMD PHYS401 SPRING 2012

Introduction to MATLAB for CSE390

Page 1 of 7 E7 Spring 2009 Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering. Practice Midterm 01

CSCI 6906: Fundamentals of Computational Neuroimaging. Thomas P. Trappenberg Dalhousie University

CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo

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.

Lecture 1: Hello, MATLAB!

Transcription:

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 command prompt is >> < Type commands or variable names and expressions, then RETURN to execute < Ending a command line with ; suppresses echoing of result, else echo occurs < Use more on and more off to toggle screen-by-screen display < Use help for general help, help command for help on specific command or function < Up arrow scrolls back through previously entered commands (& Down forward) < Highlighting and using Cut/Ctrl-x, Copy/Ctrl-c, Paste/Ctrl-v works Stopping Matlab < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c

MATLAB VARIABLES AND DATA Matlab is a calculator (so +, -, *, /, ^, sin, tan, log, exp, sqrt mean what they usually do) Matlab easily handles arrays (vectors, matrices, multidimensional arrays): < x=1 is a scalar < x=[1 2 3 4] is a row vector < x=[1 2 3 4]' or x=[1; 2; 3; 4] or x=[1 <RET> 2 <RET> 3<RET> 4] is a column vector < x=[1 2 3 4; 5 6 7 8] or x=[1 2 3 4 <RET> 5 6 7 8] is a (2x4) matrix < Variable names can be up to 31 characters long and are case-sensitive < Type variable <RET> to see its value < Type who to list all current variables < Type whos to list all current variables and their types and sizes < size(y) gives dimensions of variable y < Clear a variable name with clear variable - NOTE: clear clears EVERYTHING < Last answer is variable ans < Use format to alter display format (fixed point, scientific notation, etc.) Matlab does complex variables, too (e.g., x=6+5*i if i is not overwritten) Matlab lets you save the current variables and load previously saved data: < save file saves everything to filename file.mat (in current directory) < save file x y saves only x and y to filename file.mat (in current directory) < load file loads all variables from filename file.mat in directory path and overwrites < load dir/file loads all variables from filename file.mat (in directory dir) and overwrites < Omitting filename defaults to matlab.mat in current directory < Options exist for loading and saving ASCII text data - see help on load and save

MATLAB DIRECTORIES Matlab starts in an application-dependent default directory < pwd to see current directory < dir or ls for current directory contents < cd to change current directory < what to see Matlab files in current directory <! to execute a shell command outside of Matlab Matlab starts with an application-dependent default directory path (to look for things) < path to see current path (searches top to bottom) < path(path, dir ) to append directory dir to end of path < See help on path for other options

MATLAB AS A PROGRAMMING LANGUAGE The colon : specifies ranges of values: < x=[1:10] is x=[1 2 3 4 5 6 7 8 9 10] < x=[0:0.1:1.0] is x=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0] < Negative or variable increments and limits are OK: x=[ylow:(yhigh-ylow)/20:yhigh] < Useful for all or part of rows, columns, other dimensions of arrays: < a(3,:) is third row of a < b(:,4:5) is fourth and fifth columns of b < c(1,3,2:6) is second through sixth elements along third dimension of array c(1,3) Matlab recognizes relational operators <, >, <=, >=, ==, ~=: < For a row array x, x>=0 produces a row array with 1 where true and 0 where false < Other commands also produce 1/0 true/false logical output (e.g. isreal, isprime) Matlab does if/(then)/else, for, and while: < Must ALWAYS terminate with end < if x<=pi/2 y=sin(x) else y=-sin(x) end < y=0; for k=[0:.1:pi/2] y=[y; sin(k)]; end You can save Matlab scripts as.m (text) files: < Form a text file (using any editor, including Matlab editor) containing: y=0; for k=[0:.1:pi/2] y=[y; sin(k)]; end < Save it as file myscript.m in the current directory or in a directory on the path < Type myscript to execute it < NOTE: Re-save any changes made in an editor before re-executing < You can also define Matlab functions this way (manipulate internal variables but only the designated output variables go back to the Matlab workspace) < Within scripts (or functions), you can display things to the screen ( disp ), execute other Matlab functions or scripts, ask for user input ( input ), even pause for a specific length of time or until a keyboard key is pressed

MATLAB FOR PLOTS The key command here is plot : < plot(x,y) plots y (vertical axis) vs. x (horizontal) where x and y must be vectors that are exactly the same size with auto-scaled axis ranges < See help for plot for many other options (semilog plots, different symbols and line colors, 3-dim feather plots, etc.) < Plot appears in a separate window, labelled Figure No. X where X starts as 1 < Some operations to enhance plots: grid adds a grid, xlabel and ylabel add labels to axes, title adds title < figure in command window switches to next plot window (2 if X was 1 above) < figure(3) switches to window containing Figure No. 3 < hold on allows a new plot on same axes as previous plot ( hold off turns it off) < axis([1 6-3 4]) fixes the axis ranges to 1 to 6 along x and -3 to 4 along y, axis with no specified ranges turns auto-scaling of axes back on Once a plot is created: < You can copy it and then paste it into a word processor < You can print it < plot(x,y) plots y (vertical axis) vs. x (horizontal) where x and y must be vectors that are exactly the same size with auto-scaled axis ranges < See help for plot for many other options (semilog plots, different symbols and line colors, 3-dim feather plots, etc.) < Plot appears in a separate window, labelled Figure No. X where X starts as 1 < Some operations to enhance plots: grid adds a grid, xlabel and ylabel add labels to axes, title adds title < figure in command window switches to next plot window (2 if X was 1 above) < figure(3) switches to window containing Figure No. 3 < hold on allows a new plot on same axes as previous plot ( hold off turns it off) < axis([1 6-3 4]) fixes the axis ranges to 1 to 6 along x and -3 to 4 along y, axis with no specified ranges turns auto-scaling of axes back on