The MATLAB library of functions and IDE (Integrated Development Environment) allow one to visualize curves in the Cartesian plane. We can use the MATLAB function
sort
to sort some
uniformly distributed
numbers in the interval $[0,10]$ using the MATLAB function
rand
. We use this increasing sequence of numbers for our
abscissa
($x$) values. We can use
rand
again to obtain our ordinate ($y$) values. The
plot
function creates simple
connect-the-dots
style graph.
format short
x = sort(rand(1,10));
y = (1:10) + rand(1,10);
plot(x,y)
The first argument to the
plot
function is an array of $x$-values and the second argument is an array of $y$-values. These arrays
must
be the same size. The
plot
function graphs each coordinate pair $\left(x(i),y(i)\right)$ and draws a straight line that connects them.
One can add a third argument to
plot
; a
line specification
. A
line specification
is a string that controls the
line style
,
marker
, and
color
of the curve created. For example, if we add the string
'r*--'
, to our
plot
function, we see a red splat (asterisk) plotted at each point $\left(x(i),y(i)\right)$, and the points are joined by a red dashed line.
x = sort(rand(1,10));
y = (1:10) + rand(1,10);
plot(x,y,'r*--')
If we use the line specification
'vo'
, each point $\left(x(i),y(i)\right)$ will be
marked
with a magenta 'o', and no line will join the
markers
.
x = sort(rand(1,10));
y = (1:10) + rand(1,10);
plot(x,y,'m+')
More than one set of points can be passed to plot.
x = 10*sort(rand(1,10)) - 5;
y = (1:10) + rand(1,10);
z = (-5:5);
w = (10:-1:0) + rand(1,11);
plot(x,y, 'gd-.', z, w, 'b+:')
Once may further control the properties of a plot by adding more arguments. To mark the data points with large green squares connected by red dashed lines:
x = 10*sort(rand(1,10)) - 5;
y = (1:10) + rand(1,10);
plot(x,y,'--rs','MarkerSize',20,'MarkerFaceColor','g')
We can use the MATLAB function loglog , semilogx , and semilogy to create functions with axes set to a logarithmic scale . You should read the documentation for each of the past links to see examples of MATLAB plots one can create. One may create multiple plots using the MATLAB function figure . Mathworks supplies a variety of functions that can be used to visualize data.
x = 10*sort(rand(1,10)) - 5;
y = exp((1:10) + rand(1,10));
z = exp(-5:5);
w = (10:-1:0) + rand(1,11);
semilogy(x,y, 'r-')
figure
semilogx(z, w, 'bp:')
The appearance and even existence of the axes of a plot can be controlled by MATLAB functions to format and annotate your graphs. You can specify the appearance of the axes , display a legend , and create titles and labels for your graphs. You can create data distribution plots , geographic plots , contour plots and plot in polar coordinates .
MATLAB contains some animation functions. A more powerful technique creates a series of plots in a loop that are added to a movie file. We will explore some of these techniques in class and in your homework assignment.
Creative Commons Attribution-NonCommercial-ShareAlike 4.0
Attribution
You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
Noncommercial
You may not use the material for commercial purposes.
Share Alike
You are free to share, copy and redistribute the material in any medium or format. If you adapt, remix, transform, or build upon the material, you must distribute your contributions under the
same license
as the original.