0% found this document useful (0 votes)
68 views

2D Plots in MATLAB

This document provides an introduction to 2D plotting in MATLAB and Octave. It describes the basic plot and stairs commands to generate two-dimensional graphs from x and y data. It also covers options for customizing line styles, colors, markers, labels, titles and combining multiple graphs in a single figure window. Examples of syntax are provided for all the plotting commands and properties discussed. The document concludes with an example problem to generate five functions with customized plots in one figure window.

Uploaded by

Paul The Human
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

2D Plots in MATLAB

This document provides an introduction to 2D plotting in MATLAB and Octave. It describes the basic plot and stairs commands to generate two-dimensional graphs from x and y data. It also covers options for customizing line styles, colors, markers, labels, titles and combining multiple graphs in a single figure window. Examples of syntax are provided for all the plotting commands and properties discussed. The document concludes with an example problem to generate five functions with customized plots in one figure window.

Uploaded by

Paul The Human
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

2D Plots

INTRODUCTION TO MATLAB
ECE120L
Introduction

MatLab and Octave are both capable of generating two-dimensional


plots. These two-dimensional plots may be plotted with the use of
the command plot and stairs
Figure

The command figure calls the Figure Window of the MATLAB or


Octave.

SYNTAX: figure
Plot

The command plot(x,y) calls the Figure Window and graphs the
function y against the independent variable x using a smooth line
connecting the data points x and y

SYNTAX: plot(x,y)
Stairs

The command stairs(x,y) calls the Figure Window and graphs the
function y against the independent variable x using discrete levels
based on the data points x and y.

SYNTAX: stairs(x,y)
Line Specifications

The line specification syntax describes how to specify the properties


of lines used for plotting. This includes the line style, line color and
marker specifiers of the data points
Line Style, Color and
Marker Specifiers
Specifier Line Style Specifier Marker Type
‘-’ Solid Line (Default) ‘+’ Plus
‘--’ Dashed Line ‘o’ Circle
‘:’ Dotted Line ‘*’ Asterisk
‘-.’ Dash-dot line ‘.’ Point

Specifier Color ‘x’ Cross

r Red ‘s’ Square

g Green ‘d’ Diamond

b Blue ‘^’ Upward-pointing

c Cyan ‘v’ Downward-pointing

m Magenta ‘>’ Right-pointing

y Yellow ‘<’ Left-pointing

k Black ‘p’ Pentagram

w White ‘h’ hexagram


Line Style, Color and
Marker Specifiers
To add these specifiers to the plot or stairs graph, we us the syntax
SYNTAX: plot(x,y,’lscmt’) or stairs(x,y,’lscmt’)
Where,
ls = specifier for Line Style
c = specifier for Color
mt = specifier for Marker Type
Other Related Properties

Syntax: LineWidth — Specifies the width (in points) of the line.


Syntax: MarkerEdgeColor — Specifies the color of the marker or
the edge color for filled markers (circle, square, diamond,
pentagram, hexagram, and the four triangles).
Syntax: MarkerFaceColor — Specifies the color of the face of filled
markers.
Syntax: MarkerSize — Specifies the size of the marker in points
(must be greater than 0).
Labels and Titles

Add a title to the chart by using the title command. To display the
Greek symbol π, use the TeX markup, \pi.

SYNTAX: title(‘Title Name’)

Add axis labels to the chart by using the xlabel and ylabel functions.

SYNTAX: xlabel(‘Label for x-axis’)


SYNTAX: ylabel(‘Label for y-axis’)
Combining Graphs

To combine two or more graphs with the same x-axis variable, we


use either of the following commands:
1. SYNTAX: plot(x,y1,’lscmt’, x,y2,’lscmt’)
2. Using the hold on and hold off commands.
SYNTAX: hold on
Stem

stem(x,y) plots the data sequence, Y, at values specified by X.


The X and Y inputs must be vectors or matrices of the same size.

SYNTAX: stem(x,y)
Plate 4a

Choose five functions to graph and use all the commands presented
in this lecture.

The highly complicated graphs will be given higher points.

Each of the function should be graphed in one Figure Window with


its corresponding Title.
END

You might also like