You are on page 1of 5

MATLAB FUNDAMENTALS

4. Graphics

MATLAB allows to create graphs quickly. For example, in assignment_2 we have t variable, which
is given in the question, and v variable which we calculated.

>> t = [0:2:20]'

t=

0
2
4
6
8
10
12
14
16
18
20

>> v = sqrt(g*m/cd)*tanh(sqrt(g*cd/m)*t)

v=

0
18.8393
33.7752
43.5839
49.2540
52.2927
53.8553
54.6418
55.0334
55.2273
55.3231
>> plot(t,v) creates the below graph

But in this shape, plot is useless. We need to organize it more.

>> title('Plot of v versus t')


>> xlabel('Values of t')
>> ylabel('Values of v')
>> grid
Table_1. Specifiers for colors, symbols, and line types.
Colors Symbols Line Types
Blue b Point . Solid -
Green g Circle o Dotted :
Red r X-mark x Dashdot -.
Cyan c Plus + Dashed --
Magenta m Star *
Yellow y Square s
Black k Diamond d
White w Triangle(down) v
Triangle(up) ᴧ
Triangle(left) <
Triangle(right) >
Pentagram p
Hexagram h

As >> clear and >> clc commands, >> clf commands clear the figure window and >> close
command closes the figure window. You can play with the plot functions. Also, >>hold on
command able you to continue editing your plot. >>hold off means you finished to edit it.

>> plot(t,v,'o')
>> hold on
>> title('Time versus Velocity')
>> xlabel('time')
>> ylabel('velocity')
>> plot(t,v,'m')
>>hold off

You can find more under the plot section in help of MATLAB.

>> lookfor also a handy tool for listing the help topics. For example,
>> lookfor plot
smithbase - Base class for smithplot
cellplot - Display graphical depiction of cell array.
odeplot - Time series ODE output function.
etreeplot - Plot elimination tree.
gplot - Plot graph, as in "graph theory".
treeplot - Plot picture of tree.
cplxmap - Plot a function of a complex variable.
graf2d - 2-D Plots
graf2d2 - 3-D Plots
graf3d - Demonstrate Handle Graphics for surface plots in MATLAB.

4. Poly Graphing

>> subplot(n,m,p) command allows you to split the graph window.


>> plot3(x,y,z) command allows you to plot 3-D graphs. It is important to use vectors (x,y,z) in
same lengths.
Let’s use them in an example

>> t = 0:pi/50:10*pi;
>> subplot(1,2,1);
>> plot(sin(t), cos(t))
>> axis square
>> title('(a)')
>>
>> subplot(1,2,2);
>> plot3(sin(t),cos(t),t);
>> title('(b)')
>>
Graph should be like below

You might also like