4.1: Introduction to Graphing in MFile Environments
One of the reasons that mfile environments are extensively used by engineers is their capability to provide graphical representations of data and computed values. In this section, we introduced the basics of graphing data in mfile environments through a series of examples. This section uses some fundamental operations on vectors that are explained in Vectors and Arrays in MFile Environments in the chapter Basic Mathematical Computations.
Example 1
Table 1 shows speed as a function of distance for a braking Dodge Viper decelerating from to .
Note: This data was not measured; it was computed using the stopping distance reported for a Dodge Viper (http://www.caranddriver.com/article.asp?section_id=33&article_id=2420&page_number=2) and assuming constant deceleration. Thus, it may not accurately reflect the braking characteristics of a real Dodge Viper.
Distance (ft)  Velocity (ft/s) 

The following commands will create a graph of velocity as a function of distance:

dist = [0 29.1 55.1 78.0 97.9 114.7 128.5 139.2 146.9 151.5 153.0]

vel = [102.7 92.4 82.1 71.9 61.6 51.3 41.1 30.8 20.5 10.3 0.0]

plot(dist,vel)
Figure 1 shows the graph created by these commands.
Graph of the Viper's velocity as a function of distance.
This graph shows the data, but violates several important conventions of engineering practice. The axes are not labeled with quantities and units, and the graph does not have a title. The following commands, when executed after the plot command, will label the axes and place a title on the graph.

xlabel('Distance (ft)')

ylabel('Velocity (ft/s)')

title('Velocity vs Distance for the Dodge Viper')
The results of these commands are shown in Figure 2.
Graph of the Viper's velocity as a function of distance. The graph has a title and labels on the axes.
After creating a figure, you may wish to insert it into a document. The method to do this depends on the mfile environment, the document editor and the operating system you are using.
MATLAB, Word, and Windows: To paste a figure into a Word document on Windows, pull down the Edit menu of the window of the MATLAB figure you wish to paste, and select Copy Figure. Then go to the Word document into which you wish to insert the figure and use the paste command.
Exercise 1
Repeat Example 1 using the following data for a Hummer (http://www.caranddriver.com/article.asp?section_id=33&article_id=2420&page_number=2).
Note: As in Example 1, this data was not measured; it was computed using the stopping distance reported for a Hummer and assuming constant deceleration.
Distance (ft)  Velocity (ft/s) 

Example 2
An mfile environment can also be used to plot functions. For example, the following commands plot over one period.

x = 0:0.1:2*pi;

y=cos(x);

plot(x,y);

xlabel('x')

ylabel('cos(x)')

title('Plot of cos(x)')
Figure 3 shows the graph created by these commands.
Graph of one period of the cosine function.
Exercise 2
Exercise 3 in the chapter Basic Mathematical Computations describes how to compute the terminal velocity of a falling sky diver. Plot the terminal velocity as a function of the sky diver's weight; use weights from to .
Exercise 3
In electrical circuit analysis, the equivalent resistance of the parallel combination of two resistors and is given by the equation
Set and plot for values of from to .
Exercise 4
In an experiment, a small steel ball is dropped and its trajectory is recorded using a video camera with a checkered background behind the ball. The video sequence is analyzed to determine the height of the ball as a function of time to give the data in Table 3.
Time (s)  Height (in) 

This experimental data is to be compared to the theoretically expected values given by the following equation:
where is in inches, is in seconds,and . Create a graph that compares the measured data with the theoretically expected values; your graph should conform to good conventions for engineering graphics. Plot the measured data using red circles, and plot the theoretically expected values using a blue line.
Notes/Highlights Having trouble? Report an issue.
Color  Highlighted Text  Notes  

Please Sign In to create your own Highlights / Notes  
Show More 