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

3 - MatLab Fundamentals

MATLAB allows for quick creation of graphs. The plot command creates a graph from input vectors, and additional commands like title, xlabel, ylabel allow customization. Multiple plots can be added to the same graph using hold on/off. Subplot splits the window for multiple graphs, and plot3 creates 3D graphs from x, y, z vector inputs of the same length. MATLAB also has tools like lookfor to search documentation and list relevant help topics.

Uploaded by

Simay Oğuzkurt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

3 - MatLab Fundamentals

MATLAB allows for quick creation of graphs. The plot command creates a graph from input vectors, and additional commands like title, xlabel, ylabel allow customization. Multiple plots can be added to the same graph using hold on/off. Subplot splits the window for multiple graphs, and plot3 creates 3D graphs from x, y, z vector inputs of the same length. MATLAB also has tools like lookfor to search documentation and list relevant help topics.

Uploaded by

Simay Oğuzkurt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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