MATLAB: Plotting Functions of a Vector and Creating Graphs, Study notes of Computer Science

Instructions on how to build and plot functions of a vector using matlab. It covers creating vectors, plotting functions with different symbols and colors, adding titles, labeling axes, and creating legends. The document also introduces the subplot function for creating multiple plots in one figure and plotting two-dimensional data.

Typology: Study notes

Pre 2010

Uploaded on 07/22/2009

koofers-user-fs2
koofers-user-fs2 🇺🇸

10 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
MA/CS 375
Spring 2009
Lecture1d
Introduction to MATLAB: Plotting
Ref: Appendix B
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download MATLAB: Plotting Functions of a Vector and Creating Graphs and more Study notes Computer Science in PDF only on Docsity!

MA/CS 375

Spring 2009

Lecture1d

Introduction to MATLAB: Plotting

Ref: Appendix B

Building/plotting a function of a

vector

1) Create a vector x ,

with 50 equally

spaced entries from

0 to 1.

2) Create a vector f,

with entries of

cosine evaluated at

entries of 2pi x

3) Plot f as a function

of x , using +

symbols

Example

(Building and plotting two

functions of a vector)

1) Create a vector x , with 50
entries from 0.0 to 1.
2) Create a vector f, with
entries cos(2pi x ).
3) Create a vector g with entries
sin(2pi x )
4) Plot f as a function of x ,
using a blue line
5) On same graph plot g as a
function of x, using red +
symbols.
“hold on” instructs Matlab to keep the current graph window and its
contents open for another plot; “hold off” closes the figure for input.

Example

Adding a Title, Labeling Axes and

Legends

  • Give the graph a title

    title(„The very boring graphs');

  • Label the axis

    xlabel('x');

  • Label the y-axis

    ylabel('f,g');

  • Set up the legend box with descriptions of each

curve:

legend('f=cos(2pix)', 'g=sin(2pix)');

The labeling commands

Example

Defining Font Sizes/Types

subplot

  • If you wish to create a figure with two sub-figures you can use the subplot function: - subplot(1,2,1) specifies 1 row and 2 columns of plots and requests the first plot. - subplot(1,2,2) specifies 1 row and 2 columns of plots and requests the second plot. x = linspace(0,1,33); F = sin(pix); subplot(1,2,1), plot(x,F,'r+') xlabel('x'), ylabel('F(x)') G = cos(pix); subplot(1,2,2), plot(x,G,'b*') xlabel('x'), ylabel('G(x)')

subplot(1,2,1) subplot(1,2,2)

The Plot

A surface plot

A Contour Plot