Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 25: Exploring data

Similar presentations


Presentation on theme: "Lecture 25: Exploring data"— Presentation transcript:

1 Lecture 25: Exploring data

2 Two Dimensional Plots The xy plot is the most commonly used plot by engineers The independent variable is usually called x The dependent variable is usually called y

3 Define x and y and call the plot function

4 Engineers always add … Title X axis label, complete with units
title(‘y = cos(x)’) X axis label, complete with units xlabel(‘x-axis’) Y axis label, complete with units ylabel(‘y-axix’) Often it is useful to add a grid grid on Single quotes are used.

5 Creating multiple plots
MATLAB overwrites the figure window every time you request a new plot To open a new figure window use the figure function – for example figure(2)

6 Create multiple lines on a single graph
Each set of ordered pairs will produce a new line

7 Use alternating sets of ordered pairs
If you want to create multiple plots, all with the same x value you can… Use alternating sets of ordered pairs plot(x,y1,x,y2,x,y3,x,y4) Or group the y values into a matrix z=[y1;y2;y3;y4] plot(x,z) x = 0:pi/100:2*pi; y1 = cos(x); y2 = cos(x)*2; y3 = cos(x)*4; y4 = cos(x)*6;

8 Line, Color and Mark Style
You can change the appearance of your plots by selecting user defined line styles mark styles color Try using help plot for a list of available styles

9 Specify your choices in a string
For example plot(x, y, ':ok') strings are identified with single quotes the : means use a dotted line the o means use a circle to mark each point the letter k indicates that the graph should be drawn in black (b indicates blue)

10 Available choices Table 5. 2 Line, Mark and Color Options Line Type
Indicator Point Type Color solid - point . blue b dotted : circle o green g dash-dot -. x-mark x red r dashed -- plus + cyan c star * magenta m square s yellow y diamond d black k triangle down v triangle up ^ triangle left < triangle right > pentagram p hexagram h

11 specify the drawing parameters for each line after the ordered pairs that define the line

12 Axis scaling MATLAB automatically scales each plot to completely fill the graph If you want to specify a different axis – use the axis command axis([xmin,xmax,ymin,ymax]) axis([0, 11, 0, 200])

13 Annotating Your Plots You can also add Of course you should always add
Legends legend(‘string1’, ‘string2’, etc) The legend shows a sample of the line, and Lists the string specified. Textbox text(x_coordinate, y_coordinate, ‘string’) The box is placed at the specified x and y coordinates, and Contains the string value specified. Of course you should always add title axis labels

14 4

15 Subplots The subplot command allows you to subdivide the graphing window into a grid of m rows and n columns subplot(m,n,p) rows columns location

16 subplot(2,2,1) 2 columns 2 1 2 rows 3 4

17 2 rows and 1 column

18 Saving your plots Rerun your M-file to recreate a plot
Save the figure from the file menu using the save as… option You’ll be presented with several choices of file format such as jpeg emg (enhanced metafile) etc

19 Other Types of 2-D Plots Polar Plots Logarithmic Plots Bar Graphs
Pie Charts Histograms X-Y graphs with 2 y axes Function Plots

20 Three Dimensional Plotting
Line plots Surface plots Contour plots x = [-2:0.1:2]; y = [-2:0.1:2]; [X, Y] = meshgrid(x, y); Z = X.*exp(-X.^2 - Y.^2); surf(X, Y, Z)

21 Practice Question Q. How many times will “Winter is over!!” print out?
int main( void ) { int x = 3; int y = 1; do { printf(“Winter is over!!\n”); if (x > y) { x = 0; y = 2; } x++; } while (x < y); It may never stop printing. 1 2 3 Solution: D


Download ppt "Lecture 25: Exploring data"

Similar presentations


Ads by Google