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

Size: px
Start display at page:

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

Transcription

1 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 package, but it has a nice set of graphics functions that you can use with little extra effort, even if you don t use matlab for the rest of the assignment. Thus, you can do the computations in the homework in your favourite language, then print the data to a file and call matlab to read the file and plot the results. Starting matlab and getting help To start matlab type matlab at the command prompt. The appearance of the matlab >> prompt marks the beginning of the matlab session. If you want to temporarily change the working directory, you need to use cd command in the command window.pwd is the command to get the current working directory path. Below is the example: >> cd( D:\temp ) changing the working directory to the path D:\temp >> pwd ans= D:\temp To get online help you can type help, helpwin, or helpdesk. help prints a summary of help topics. By typing help topic you get a list of functions available in that topic. For example, help graphics lists all available 2-D graphics functions. Typing help help tells you more about the help facilities. help function gives help on a specific function. helpwin opens a window in which you can browse through help topics and demos, see tips, etc.

2 helpdesk starts a browser window where you can find all of the above plus manuals, other product documentation, do full-text search, etc. 2 Variables In matlab, each variable is a matrix. A text is a string characters, all the other variables are matrices of floating point numbers. The assignement sign is = and +, -, *, / have the usual meanings. To get more info about the operators, type help arith for arithmetic operators and help relop for relational operators (i.e,, etc.). Below are some examples: >> A = [ ; ] a matrix A = >> B = [ 2 ] a row vector B = 2 >> C = B the transposes a matrix C = 2 >> >> A(,2) = B( 3) A 2 gets the value of B 3 A = >> A(,:) the first row of A ans = 2

3 2 2 4 >> A(:,2:3) all the rows of A but only columns 2 thru 3 ans = >> x = :8 creates a vector containing the numbers to 8 x = >> y = :.: a vector containing a progression from to with increment. y = Columns through Columns 8 through >> y(2:6) ans = In the following I assume that you have created a data file example.dat containing the results of some experiment and that you want to use matlab to plot these results. An example script is contained in the file h example.m which is reproduced in section 9. Matlab commands can be typed at the prompt or typed in a script file. The standard extension for a script file is.m. tips: Ending a command by semicolon (";"), the result will not print after the command. 3

4 3 Reading files with matlab In Matlab, there are three common methods to read data from text files. 3. Using function textread to read files textread is a function to read data from text files and write to multiple outputs. The syntax is: [A,B,C,...]=textread( filename, format ) or [A,B,C,...]=textread( filename, format,n). This command read data from the specified filename and write to the output [A,B,C,...]. The format string determines the number and types of return arguments. N determines the number of times to reuse the format string. Examples:The data in the file test.dat is Mary Level 45 Jerry Level2 34 Mike Level3 36 Susan Level2 4 >>[names,level,age]=textread( test.dat, %s %s %d ) read the entire file names = Mary, Jerry, Mike, Susan level = Level, Level2, Level3, Level2 age = 45,34,36,4 >>[names,level,age]=textread( test.dat, %s %s %d,) read the first line names= Mary level= Level age= 45 The data file example.dat:

5 Then the code A=textread( example.dat, %d,3) will read the first 3 intergers from the file. The A is a 3-by- column vector. 3.2 Using function textscan When we need to read data from a large text file, or want to read from a specific point of a file, the function textscan will be a better choice. It can read a specified amount of data from a file, and maintain a pointer to the location in the file where the last read operation ended. The function will write the data to a cell array instead of multiple outputs. Cell arrays in MATLAB are multidimensional arrays whose elements are copies of other arrays. Before using this function, we must need to use fopen function to open the file and supply the fid information which is required in the function.for detail descriptions for fopen and fid, you can refer to next section. The syntax for textscan is: C = textscan(fid, format ) or C = textscan(fid, format, N) The format string determines the number and types of return arguments. N determines the number of times to reuse the format string. Examples: The code is to read data from the example.dat described in previous subsection >> fid=fopen( example.dat ); % open the file example.dat >> A=textscan(fid, %d,3); % read the first 3 integers from the file and write into A, then A{} is a 3-by- column vector >> B=textscan(fid, %f ); % this command will read the left numbers and write into the cell array B >> flcose(fid); % close the file 3.3 Using function fscanf to read files First, you need to open the file in order to read the data from it. To open a file use the command fopen: fin = fopen( example.dat, r ); The above command opens the file example.dat for reading, as indicated by the second parameter r. A file identifier is returned in the variable fin. 5

6 The data file is an ASCII file given in section 9 and you can do formatted reading from it. The syntax is similar to the C syntax. [A,COUNT] = fscanf(fid,format,size) reads data from the file specified by file identifier FID, converts it according to the specified FORMAT string, and returns it in matrix A. COUNT is an optional output argument that returns the number of elements successfully read. FID is an integer file identifier obtained from fopen. SIZE is optional; it puts a limit on the number of elements that can be read from the file; if not specified, the entire file is considered; if specified, valid entries are: N read at most N elements into a column vector. inf read to the end of the file. [M,N ] read at most M * N elements filling an M-by-N matrix, in column order. N can be inf (the symbol for infinity), but not M. FORMAT is a string containing C language conversion specifications. fscanf differs from its C language namesake in an important respect - it is vectorized in order to return a matrix argument. The format string is recycled through the file until an end-of-file is reached or the amount of data specified by SIZE is read in. Examples: S = fscanf(fid, %s ) reads (and returns) a character string A = fscanf(fid, %5d ) reads 5-digit decimal integers integer data = fscanf( fin, %d, [, 3 ] ) reads a vector of 3 integers; in the data file, the numbers are separated by blank spaces float data = fscanf( fin, %f, [ 2, 2 ] ) reads a 2 by 2 matrix of blank-separated real numbers When you are finished with a file, close it using the handle and the command fclose: fclose( fin ); Alternatively, you can use the following commands to read in a file. Assume that you have a file called data.txt containing three columns of data (e.g. the weight, height and age of individuals) that are space-delimited dlmread( data.txt, ); %read in the file and store the data in ans weight = ans(:, ); %extract the first column into weight height = ans(:, 2); %extract the second column into height age = ans(:, 3); %extract the third column into age 6

7 plot(weight, height, age); % make use the data e.g. plot a graph 4 Displaying data and inserting comments To display any variable or expression in matlab, type its name at the prompt: integer data prints the vector integer data 3 * ^2 prints the value of the expression Note: if you want an expression to be displayed, do NOT end the statement with ; (semicolon). A semicolon at the end of an expression or statement is optional and its action is to supress the display of the result. The symbol % marks the beginning of a comment. Everything after it in the command line is ignored. Example: x = sort( float data(, : )); % copy row of float data % into x and sort it y = float data( 2, : ); % copy row 2 of float data % into vector y 5 Making a histogram Matlab has the built-in command hist for making a histogram. Its syntax is: hist(y) bins the elements of Y into equally spaced bins. If Y is a matrix, hist works down the columns. hist(y,m), where M is a scalar, uses M bins. Examples: hist( integer data ) histogram with bins hist( integer data, 6 ) histogram with 6 bins 6 Making a plot The function for making plots in matlab is plot. plot(x,y) plots vector Y versus vector X. plot(y) plots the columns of Y versus their index. If Y is complex, plot(y) is equivalent to plot(real(y),imag(y)). 7

8 Various line types, plot symbols and colors may be obtained with plot(x,y,s) wheresis a character string made from one element from any or all the following 3 columns: plot(x,y,s,x2,y2,s2,x3,y3,s3,...) combines the plots defined by the (X,Y,S) triples, where the X s and Y s are vectors or matrices and the S s are strings. color marker type line type y yellow. point - solid m magenta o circle : dotted c cyan x x-mark -. dashdot r red + plus dashed g green * star b blue s square w white d diamond k black v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram For example: plot(x,y, c+: ) plots a cyan dotted line with a plus at each data point; plot(x,y, bd ) plots blue diamond at each data point but does not draw any line. plot(x,y, y-,x,y, go ) plots the data twice, with a solid yellow line interpolating green circles at the data points. The commands title, xlabel, ylabel let you annotate a plot. title( text ) writes the texttext above the plot as a title. The commandsxlabel( text ), ylabel( text ) label the X and Y axes respectively. For example (see also figure 3): plot( x, y ); % plot y vs x xlabel( x ); ylabel( y ); title( An x-y plot ); To make multiple plots on the same figure, use the command subplot. subplot(m,n,p), or subplot(mnp), breaks the Figure window into an m-by-n matrix of small subplots and selects the p-th subplot for for the current plot. The subplots are counted along the top row of the Figure window, then the second row, etc. For example, subplot(2,3,) % divide the display into 2x3 subplots 8

9 and go % to subplot plot( float data(,: )) % plot something title( float data row ); subplot(232) % now go to second subplot plot( float data(,: ), o ) % plot the same data as before, % but with circles instead of continuous line title( float data row ); subplot(233) % go to third subplot 7 Printing a figure Once a figure is ready, you need to output it by printing it to a file. The print command allows you to do so. print alone sends the current figure to your current printer. print -device -options You can optionally specify a print device (i.e., an output format such as tiff or PostScript or a print driver that controls what is sent to your printer) and options that control various characteristics of the printed file (i.e., the resolution, type of preview, Figure to print etc.). Available devices and options are described by typing help print. print -device -options filename If you specify a filename, matlab directs output to a file instead of a printer. print adds the appropriate file extension if you do not specify one. The implicit format used if you do not specify any device/option is Postscript. When a figure is divided into several subplots, the print command prints all of them in one file.:383 Examples: print histogram.ps saves the current figure into the Postscript file histogram.ps print myfigure saves the current figure into into the Postscript file figure.eps print -depsc -tiff -r3 matilda Saves current Figure at 3 dpi in color EPS to matilda.eps with a TIFF preview (always at 72 dpi). This TIFF preview will show up on screen if matilda.eps is Inserted as a Picture in a Word document, but the EPS will be used if the Word document is printed on a PostScript printer. 9

10 8 Generating random numbers rand and randn are two functions used to generate random numbers in Matlab. rand is used to generate uniformly distributed random numbers and arrays. randn is used to generate normally distributed random numbers and arrays. rand(n) return an n-by-n matrix with random numbers which are from a uniform distribution in the interval (,) rand(m,n) return an m-by-n matrix with random numbers which are from a uniform distribution in the interval (,) randn(n) return an n-by-n matrix with random numbers which are from a normal distribution with mean, variance σ 2 = randn(m,n) return an m-by-n matrix with random numbers which are from a normal distribution with mean, variance σ 2 = >> A=rand(2) return a 2-by-2 matrix A = >> B = rand(,3) return a -by-3 matrix B = >> C = randn(2) random numbers from normal distribution C = >> D=randn(,4) random numbers from normal distribution D =

11 9 An example This is a sequence of matlab commands that reads data from a file, makes some plots and prints them out. The commands are in the file example.m. The data is in file and the printouts are shown in figures, 2, 3. % open file example.dat and read the data fin = fopen( example.dat, r ); integer data = fscanf( fin, %d, [, 3 ] ); % read 3 integers % and store them in the x3 matrix integer data float data = fscanf( fin, %f, [ 2, 2 ] ); % read 4 floating point % numbers and store them in the 2x2 matrix float data fclose( fin ); % display the data integer data float data % make a histogram and print it to file histogram.ps hist( integer data ); xlabel( integer data ); title( histogram of integer data ); print histogram.ps % plot the first row of float data and print the graph to file float data.ps plot( float data(, : ) ); ylabel( float-data row ); print float data.ps % make six plots on one page and print them to file float data.ps subplot(23) % divide the display into 2x3 subplots and go to subplot plot( float data(,: )) % plot the same data as before title( float data row ); subplot(232) % now go to second subplot

12 plot( float data(,: ), o ) % plot the same data as before, but with circles % instead of continuous line title( float data row ); subplot(233) % go to third subplot x = sort( float data(, : )); % copy row of float data into x and sort it y = float data( 2, : ); % copy row 2 of float data into vector y plot( x, y ); % plot y vs x xlabel( x ); ylabel( y ); title( An x-y plot ); subplot( 234 ); % now make same plot with different line style plot( x, y, :, x, y, ^ ); % plots once with dotted line and once with % triangles on the same graph xlabel( x ); ylabel( y ); title( Another x-y plot ); subplot(235) x2 = :.5:; % generate the vector [ ] % with 2 elements y2 = sin( 3 * x2 ); plot( x, y, --, x2, y2, * ); % plot y vs x with dashed line and % y2 vs x2 with * on the same graph xlabel( x, x2 ); ylabel( y, y2 ); title( Two x-y plots on the same graph ); subplot(236) % a histogram of integer data with 6 bins hist( integer data, 6 ); xlabel( integer data ); ylabel( # points ); title( histogram with 6 bins ); print float data.ps The data file example.dat:

13 8 histogram of integer_data integer d ata x 4 Figure : The figure in histogram.ps float data row Figure 2: The figure in float data.ps

14 2 float d ata row 2 float d ata row 2 An x y plot y x 2 Another x y plot Two x y plots on the same graph 2 2 histogram with 6 bins 5 y y, y2 # points x x, x integer_data x 4 Figure 3: The figure in float data.ps. 4

Matlab Tutorial 1: Working with variables, arrays, and plotting

Matlab Tutorial 1: Working with variables, arrays, and plotting Matlab Tutorial 1: Working with variables, arrays, and plotting Setting up Matlab First of all, let's make sure we all have the same layout of the different windows in Matlab. Go to Home Layout Default.

More information

Mechanical Engineering Department Second Year (2015)

Mechanical Engineering Department Second Year (2015) Lecture 7: Graphs Basic Plotting MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. This section describes a few of the most

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

QUICK INTRODUCTION TO MATLAB PART I

QUICK INTRODUCTION TO MATLAB PART I QUICK INTRODUCTION TO MATLAB PART I Department of Mathematics University of Colorado at Colorado Springs General Remarks This worksheet is designed for use with MATLAB version 6.5 or later. Once you have

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

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

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

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed. Example 4 Printing and Plotting Matlab provides numerous print and plot options. This example illustrates the basics and provides enough detail that you can use it for typical classroom work and assignments.

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

This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in

This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in subsequent modules to help to teach research related concepts

More information

Introduction to Matlab

Introduction to Matlab What is Matlab? Introduction to Matlab Matlab is software written by a company called The Mathworks (mathworks.com), and was first created in 1984 to be a nice front end to the numerical routines created

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

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression.

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression. What is the answer? >> Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression. The finite(x)is true for all finite numerical

More information

Additional Plot Types and Plot Formatting

Additional Plot Types and Plot Formatting Additional Plot Types and Plot Formatting The xy plot is the most commonly used plot type in MAT- LAB Engineers frequently plot either a measured or calculated dependent variable, say y, versus an independent

More information

Basic plotting commands Types of plots Customizing plots graphically Specifying color Customizing plots programmatically Exporting figures

Basic plotting commands Types of plots Customizing plots graphically Specifying color Customizing plots programmatically Exporting figures Basic plotting commands Types of plots Customizing plots graphically Specifying color Customizing plots programmatically Exporting figures Matlab is flexible enough to let you quickly visualize data, and

More information

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College Introduction to Matlab to Accompany Linear Algebra Douglas Hundley Department of Mathematics and Statistics Whitman College August 27, 2018 2 Contents 1 Getting Started 5 1.1 Before We Begin........................................

More information

Chapter 3: Introduction to MATLAB Programming (4 th ed.)

Chapter 3: Introduction to MATLAB Programming (4 th ed.) Chapter 3: Introduction to MATLAB Programming (4 th ed.) Algorithms MATLAB scripts Input / Output o disp versus fprintf Graphs Read and write variables (.mat files) User-defined Functions o Definition

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

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab Islamic University of Gaza Faculty of Engineering Electrical Engineering Department 2012 DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab Goals for this Lab Assignment: In this lab we would have

More information

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as Geog 271 Geographic Data Analysis Fall 2015 PyPlot Graphicscanbeproducedin Pythonviaavarietyofpackages. We willuseapythonplotting package that is part of MatPlotLib, for which documentation can be found

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 4 Visualising Data Dr Richard Greenaway 4 Visualising Data 4.1 Simple Data Plotting You should now be familiar with the plot function which is

More information

Matlab Tutorial and Exercises for COMP61021

Matlab Tutorial and Exercises for COMP61021 Matlab Tutorial and Exercises for COMP61021 1 Introduction This is a brief Matlab tutorial for students who have not used Matlab in their programming. Matlab programming is essential in COMP61021 as a

More information

Matlab Tutorial for COMP24111 (includes exercise 1)

Matlab Tutorial for COMP24111 (includes exercise 1) Matlab Tutorial for COMP24111 (includes exercise 1) 1 Exercises to be completed by end of lab There are a total of 11 exercises through this tutorial. By the end of the lab, you should have completed the

More information

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab Overview Lecture 13: Graphics and Visualisation Graphics & Visualisation 2D plotting 1. Plots for one or multiple sets of data, logarithmic scale plots 2. Axis control & Annotation 3. Other forms of 2D

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

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

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University Interactive Computing with Matlab Gerald W. Recktenwald Department of Mechanical Engineering Portland State University gerry@me.pdx.edu Starting Matlab Double click on the Matlab icon, or on unix systems

More information

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as Geog 271 Geographic Data Analysis Fall 2017 PyPlot Graphicscanbeproducedin Pythonviaavarietyofpackages. We willuseapythonplotting package that is part of MatPlotLib, for which documentation can be found

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

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

1. Register an account on: using your Oxford address

1. Register an account on:   using your Oxford  address 1P10a MATLAB 1.1 Introduction MATLAB stands for Matrix Laboratories. It is a tool that provides a graphical interface for numerical and symbolic computation along with a number of data analysis, simulation

More information

2 Amazingly Simple Example Suppose we wanted to represent the following matrix 2 itchy = To enter itchy in Matla

2 Amazingly Simple Example Suppose we wanted to represent the following matrix 2 itchy = To enter itchy in Matla Superlative-Laced Matlab Help for ECE155 Students Brian Kurkoski kurkoski@ucsd.edu October 13, 1999 This document is an introduction to Matlab for ECE155 students. It emphasizes the aspects of Matlab that

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab November 22, 2013 Contents 1 Introduction to Matlab 1 1.1 What is Matlab.................................. 1 1.2 Matlab versus Maple............................... 2 1.3 Getting

More information

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1 Chapter 2 (Part 2) MATLAB Basics dr.dcd.h CS 101 /SJC 5th Edition 1 Display Format In the command window, integers are always displayed as integers Characters are always displayed as strings Other values

More information

MATLAB Tutorial III Variables, Files, Advanced Plotting

MATLAB Tutorial III Variables, Files, Advanced Plotting MATLAB Tutorial III Variables, Files, Advanced Plotting A. Dealing with Variables (Arrays and Matrices) Here's a short tutorial on working with variables, taken from the book, Getting Started in Matlab.

More information

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens. PC-MATLAB PRIMER This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens. >> 2*3 ans = 6 PCMATLAB uses several lines for the answer, but I ve edited this to save space.

More information

MATLAB SUMMARY FOR MATH2070/2970

MATLAB SUMMARY FOR MATH2070/2970 MATLAB SUMMARY FOR MATH2070/2970 DUNCAN SUTHERLAND 1. Introduction The following is inted as a guide containing all relevant Matlab commands and concepts for MATH2070 and 2970. All code fragments should

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

What is Matlab? A software environment for interactive numerical computations

What is Matlab? A software environment for interactive numerical computations What is Matlab? A software environment for interactive numerical computations Examples: Matrix computations and linear algebra Solving nonlinear equations Numerical solution of differential equations Mathematical

More information

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb Making Plots with Matlab (last updated 5/29/05 by GGB) Objectives: These tutorials are

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 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 Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations MATLAB Tutorial The following tutorial has been compiled from several resources including the online Help menu of MATLAB. It contains a list of commands that will be directly helpful for understanding

More information

GUI Alternatives. Syntax. Description. MATLAB Function Reference plot. 2-D line plot

GUI Alternatives. Syntax. Description. MATLAB Function Reference plot. 2-D line plot MATLAB Function Reference plot 2-D line plot GUI Alternatives Use the Plot Selector to graph selected variables in the Workspace Browser and the Plot Catalog, accessed from the Figure Palette. Directly

More information

Beyond the Mouse A Short Course on Programming

Beyond the Mouse A Short Course on Programming 1 / 14 Beyond the Mouse A Short Course on Programming 5. Matlab IO: Getting data in and out of Matlab Ronni Grapenthin and Glenn Thompson Geophysical Institute, University of Alaska Fairbanks October 10,

More information

Graphics Example a final product:

Graphics Example a final product: Basic 2D Graphics 1 Graphics Example a final product: TITLE LEGEND YLABEL TEXT or GTEXT CURVES XLABEL 2 2-D Plotting Specify x-data and/or y-data Specify color, line style and marker symbol (Default values

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

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

INC151 Electrical Engineering Software Practice. MATLAB Graphics. Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1

INC151 Electrical Engineering Software Practice. MATLAB Graphics. Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1 INC151 Electrical Engineering Software Practice MATLAB Graphics Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1 Graphical display is one of MATLAB s greatest strengths and most

More information

MATLAB Introduction. Contents. Introduction to Matlab. Published on Advanced Lab (

MATLAB Introduction. Contents. Introduction to Matlab. Published on Advanced Lab ( Published on Advanced Lab (http://experimentationlab.berkeley.edu) Home > References > MATLAB Introduction MATLAB Introduction Contents 1 Introduction to Matlab 1.1 About Matlab 1.2 Prepare Your Environment

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

Purpose of the lecture MATLAB MATLAB

Purpose of the lecture MATLAB MATLAB Purpose of the lecture MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course This lecture contains a short introduction to the MATLAB For further details see other sources

More information

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Prof. Manoochehr Shirzaei. RaTlab.asu.edu RaTlab.asu.edu Introduction To MATLAB Introduction To MATLAB This lecture is an introduction of the basic MATLAB commands. We learn; Functions Procedures for naming and saving the user generated files

More information

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB 1 INTRODUCTION TO MATLAB PLOTTING WITH MATLAB Plotting with MATLAB x-y plot Plotting with MATLAB MATLAB contains many powerful functions for easily creating plots of several different types. Command plot(x,y)

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

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

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

Introduction to MATLAB: Graphics

Introduction to MATLAB: Graphics Introduction to MATLAB: Graphics Eduardo Rossi University of Pavia erossi@eco.unipv.it September 2014 Rossi Introduction to MATLAB Financial Econometrics - 2014 1 / 14 2-D Plot The command plot provides

More information

Chapter 11 Input/Output (I/O) Functions

Chapter 11 Input/Output (I/O) Functions EGR115 Introduction to Computing for Engineers Input/Output (I/O) Functions from: S.J. Chapman, MATLAB Programming for Engineers, 5 th Ed. 2016 Cengage Learning Topics Introduction: MATLAB I/O 11.1 The

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 INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs).

MATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs). L A B 6 M A T L A B MATLAB INTRODUCTION Matlab is a commercial product that is used widely by students and faculty and researchers at UTEP. It provides a "high-level" programming environment for computing

More information

Basic Graphs. Dmitry Adamskiy 16 November 2011

Basic Graphs. Dmitry Adamskiy 16 November 2011 Basic Graphs Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 16 November 211 1 Plot Function plot(x,y): plots vector Y versus vector X X and Y must have the same size: X = [x1, x2 xn] and Y = [y1, y2,, yn] Broken

More information

PROGRAMMING WITH MATLAB WEEK 6

PROGRAMMING WITH MATLAB WEEK 6 PROGRAMMING WITH MATLAB WEEK 6 Plot: Syntax: plot(x, y, r.- ) Color Marker Linestyle The line color, marker style and line style can be changed by adding a string argument. to select and delete lines

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab What is Matlab The software program called Matlab (short for MATrix LABoratory) is arguably the world standard for engineering- mainly because of its ability to do very quick prototyping.

More information

ES 117. Formatted Input/Output Operations

ES 117. Formatted Input/Output Operations ES 117 Formatted Input/Output Operations fpintf function writes formatted data in a user specified format to a file fid fprintf Function Format effects only the display of variables not their values through

More information

Computer Programming in MATLAB

Computer Programming in MATLAB Computer Programming in MATLAB Prof. Dr. İrfan KAYMAZ Engineering Faculty Department of Mechanical Engineering Arrays in MATLAB; Vectors and Matrices Graphing Vector Generation Before graphing plots in

More information

Lecture 7. MATLAB and Numerical Analysis (4)

Lecture 7. MATLAB and Numerical Analysis (4) Lecture 7 MATLAB and Numerical Analysis (4) Topics for the last 2 weeks (Based on your feedback) PDEs How to email results (after FFT Analysis (1D/2D) Advanced Read/Write Solve more problems Plotting3Dscatter

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 58:110 Computer-Aided Engineering Spring 2005 Introduction to MATLAB Department of Mechanical and industrial engineering January 2005 Topics Introduction Running MATLAB and MATLAB Environment Getting help

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

Chapter 2. MATLAB Fundamentals

Chapter 2. MATLAB Fundamentals Chapter 2. MATLAB Fundamentals Choi Hae Jin Chapter Objectives q Learning how real and complex numbers are assigned to variables. q Learning how vectors and matrices are assigned values using simple assignment,

More information

Basic Beginners Introduction to plotting in Python

Basic Beginners Introduction to plotting in Python Basic Beginners Introduction to plotting in Python Sarah Blyth July 23, 2009 1 Introduction Welcome to a very short introduction on getting started with plotting in Python! I would highly recommend that

More information

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

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name: 1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write

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

Introduction to Scientific Programming in MATLAB

Introduction to Scientific Programming in MATLAB Introduction to Scientific Programming in MATLAB Derrick Kearney HUBzero Platform for Scientific Collaboration Purdue University Original slides by Michael McLennan This work licensed under Creative Commons

More information

Spring 2010 Instructor: Michele Merler.

Spring 2010 Instructor: Michele Merler. Spring 2010 Instructor: Michele Merler http://www1.cs.columbia.edu/~mmerler/comsw3101-2.html Type from command line: matlab -nodisplay r command Tells MATLAB not to initialize the visual interface NOTE:

More information

CSE 123. Lecture 9. Formatted. Input/Output Operations

CSE 123. Lecture 9. Formatted. Input/Output Operations CSE 123 Lecture 9 Formatted Input/Output Operations fpintf function writes formatted data in a user specified format to a file fid fprintf Function Format effects only the display of variables not their

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

A General Introduction to Matlab

A General Introduction to Matlab Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html A General Introduction to Matlab e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti

More information

GRAPHICS AND VISUALISATION WITH MATLAB

GRAPHICS AND VISUALISATION WITH MATLAB GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Des Ryan & Mike Griffiths September 2017 Topics 2D Graphics 3D Graphics Displaying Bit-Mapped Images Graphics with Matlab

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

Lab #1 Revision to MATLAB

Lab #1 Revision to MATLAB Lab #1 Revision to MATLAB Objectives In this lab we would have a revision to MATLAB, especially the basic commands you have dealt with in analog control. 1. What Is MATLAB? MATLAB is a high-performance

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

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square Matlab Lecture 1 - Introduction to MATLAB Five Parts of Matlab MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-touse

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

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

5. MATLAB I/O 1. Beyond the Mouse GEOS 436/636 Jeff Freymueller, Sep 26, The Uncomfortable Truths Well, hop://xkcd.com/568 (April 13, 2009)

5. MATLAB I/O 1. Beyond the Mouse GEOS 436/636 Jeff Freymueller, Sep 26, The Uncomfortable Truths Well, hop://xkcd.com/568 (April 13, 2009) 5. MATLAB I/O 1 Beyond the Mouse GEOS 436/636 Jeff Freymueller, Sep 26, 2017 The Uncomfortable Truths Well, hop://xkcd.com/568 (April 13, 2009) Topics Loading and Saving the Workspace File Access Plo$ng

More information

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

Introduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018) Introduction to MATLAB Programming Chapter 3 Linguaggio Programmazione Matlab-Simulink (2017/2018) Algorithms An algorithm is the sequence of steps needed to solve a problem Top-down design approach to

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

Basic Plotting. All plotting commands have similar interface: Most commonly used plotting commands include the following.

Basic Plotting. All plotting commands have similar interface: Most commonly used plotting commands include the following. 2D PLOTTING Basic Plotting All plotting commands have similar interface: y-coordinates: plot(y) x- and y-coordinates: plot(x,y) Most commonly used plotting commands include the following. plot: Draw a

More information

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

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

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

MATLAB GUIDE UMD PHYS375 FALL 2010

MATLAB GUIDE UMD PHYS375 FALL 2010 MATLAB GUIDE UMD PHYS375 FALL 200 DIRECTORIES Find the current directory you are in: >> pwd C:\Documents and Settings\ian\My Documents\MATLAB [Note that Matlab assigned this string of characters to a variable

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

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau) Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau) January 24, 2010 Starting Under windows Click on the Start menu button

More information

MATLAB GUIDE UMD PHYS401 SPRING 2012

MATLAB GUIDE UMD PHYS401 SPRING 2012 MATLAB GUIDE UMD PHYS40 SPRING 202 We will be using Matlab (or, equivalently, the free clone GNU/Octave) this semester to perform calculations involving matrices and vectors. This guide gives a brief introduction

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

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

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB? Experiment 1: Introduction to MATLAB I Introduction MATLAB, which stands for Matrix Laboratory, is a very powerful program for performing numerical and symbolic calculations, and is widely used in science

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