3 - MatLab Fundamentals
3 - 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
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
>> 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