learningMatlab

Plotting data

Let’s write a script to do the following things in sequence (include comments at each step!):

>> doc plot  % if in doubt check help

more plotting…

There are many plotting / graphing related functions. Briefly play around with the following:

The plot command is very versatile and you’ll see people use it in many different ways. If you read the help/documentation for the command you’ll see that the first/normal use is to provide both x and y coordinates for the points you want to plot, e.g.:

x = 1:10;
y = rand(1,10); % 10 random numbers
plot(x,y) % simple plot
plot(x,y, 'rs--') % plot with line style
%
y2 = rand(1,10); % another 10 numbers
plot(x,y, 'rs--', x,y2, 'bo-') % two plots in one

Function exercises

'linewidth', 2   % or whichever thickness you like
'color', [1 1 0] % or some other color triplet in red, green, blue
'markersize', 15
'marker', 's'

Next

Loops, if/else, controlling flow - loops and controls