Lecture 4 Plotting Signals in MATLAB By Adal

Lecture 4: Plotting Signals in MATLAB By: Adal ALashban 1

Outline - Graph in Mat. Lab - 2 -D plotting 1. 2. 3. 4. Creating and Type of graph Using Basic Plotting Functions Plotting Multiple graph in same plot Formatting plots 2

Creating Graph in MATLAB Pie Charts, Bar Plots, and Histograms Line Plot Command Description Plot, plot 3 Create 2 -D graph and 3 -D plotyy 2 -D line plots with y-axes on both left and right side Description bar, bar 3 Bar graph 2 -D, 3 -D Pie, pie 3 Pie graph 2 -D, 3 -D hist Histogram plot Discrete Graph Command Description Stem, stem 3 Plot discrete sequence data 2 -D, 3 -D stairs Stairstep graph 3

2 -D Plotting - Specify x-data and/or y-data - Specify color, line style and marker symbol (Default values used if ‘clm not specified) - Syntax: 1. Plotting single line: plot(xdata, ydata, 'color_linestyle_marker') 1. Plotting multiple lines: plot(x 1, y 1, 'clm 1', x 2, y 2, 'clm 2', . . . ) 4

Line Specification - Three components can be specified in the string specifiers along with the plotting command. They are: 1. Line style 2. Marker symbol 3. Color Line style Specifiers Meaning '-' Solid line (default) '--' Dashed line ': ' Dotted line '-. ' Dash-dot line 5

Line Specification Color Specifiers Meaning b Blue Marker Meaning o circle v down d diamond < triangle left c Cyan h hexagram > triangle right g Green k Black m Magenta r Red y Yellow p pentagram ^ + plus x . point s square * star up triangle x -mark 6

2 -D Plotting - Example - Create a Blue Sine Wave » x = 0: . 1: 2*pi; » y = sin(x); » plot(x, y) 7

Adding a Grid - GRID ON creates a grid on the current figure - GRID OFF turns off the grid from the current figure - GRID toggles the grid state » grid on 8

Controlling the Axes - Setting Axis Limits & Grids The axis command lets you to specify your own limits: axis([xmin xmax ymin ymax]) You can use the axis command to make the axes visible or invisible: axis on / axis off The grid command toggles grid lines on and off: grid on / grid off 9

Using Basic Plotting Functions - The following commands are useful when plotting: Note that all text must be put within ' '. Graphing functions MATLAB command Label the horizontal axis. xlabel('text') Label the vertical axis. ylabel('text') Attach a title to the plot. title('text') Change the limits on the x and y axis([xmin xmax ymin ymax]) "Keep plotting in the same window. " hold on Turn off the "keep-plotting-in-the-samewindow-command". hold off using the strings to label various curves Places the string (text) on the plot at coordinate x, y relative to the plot axes. legend(‘string 1’, ’string 2’, ’st ring 3’) text(x, y, ’string’) 10

Adding Additional Plots to a Figure PLOTTING MULTIPLE GRAPHS IN THE SAME PLOT Plotting two (or more) graphs in one plot: 1. Using the plot command. 2. Using the hold on, hold off commands. 11

Subplots

Formatting Plots - A plot can be formatted to have a required appearance. - With formatting you can: 1. Add title to the plot. 2. Add labels to axes. 3. Change range of the axes. 4. Add legend. 5. Add text blocks. 6. Add grid. 13

Thank You 14
- Slides: 14