{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

PlotWithMatlab - Dr Dobbs Howto Create a scatter plot in...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Dr. Dobbs’ Howto: Create a scatter plot in Matlab This howto document walks you through the creation of an x-y 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 x-data with 8 points from 1 to 8. For the x-data 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 y-data: >> 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 data-point. >> plot(x,y,'.','MarkerSize',20,'MarkerEdgeColor','black')
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}