Dr. Dobbs’ Howto: Create a scatter plot in Matlab
This howto document walks you through the creation of an xy scatter plot, and drawing a line
through it in Matlab.
1.
Open matlab. Start
Æ
All Programs
Æ
Matlab
Æ
Matlab.
2.
Let’s create some a vector of xdata with 8 points from 1 to 8. For the xdata we use the
notation [1:1:8] , where 1 to 8 is the range for the data, and 1 is the interval
>> x= [1:1:8]
x =
1
2
3
4
5
6
7
8
3.
and the ydata:
>> y = [4.81,7.72,8.41,13.18,12.86,15.11,18.06,19.05]
4.
And let’s plot it the simplest way possible
>> plot(x,y)
hmm, that’s ugly, and isn’t the type of scatter plot we were after. Matlab has joined the
points with straight blue lines by default. Let’s look up some options for the plot
command in Matlab
Æ
help
Æ
index
Æ
“plot”, and to draw plot dots for each datapoint.
>> plot(x,y,'.','MarkerSize',20,'MarkerEdgeColor','black')
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This looks much better.
5.
Now let’s add a grid to the plot and label the axes
grid
xlabel('Time [seconds]')
ylabel('distance [meters]')
6.
Method 1 (Simple, but not very powerful): Now let’s superimpose a line yy = 2xx + 3.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '07
 Dobbs
 matlab, Computer file, Scatter plot, Portable Network Graphics, Programs Matlab Matlab.

Click to edit the document details