Hints on Graphing

Hints for plotting the data in Matlab
Hints for plotting the data in Microsoft Excel


Hints for plotting the data in Matlab

  1. Download the data file.
  2. Open Matlab and change your directory to where you saved your file.
  3. Edit the file to remove all the text data (details about the sample and data) written at the starting of the file. Save the data file as name.txt file. (Matlab does not read the values if there is text at the beginning of the data file). Make sure that you do not overwrite the original file since you need the header information for data reduction at a later stage.
  4. Now load the file in matlab by typing the following command at the command line prompt.
  5. >load name.txt

  6. To plot (lets say column 3 and column 5) of the data file, use the command >plot(name(:,3),name(:,5))
  7. This command plots column 3 on the x-axis and column 5 on the y axis.If you need to rescale some particular column and then plot the data, you can use the same command with modifications. For example, if you need to multiply ‘column 3’ by (pi/180), then you can use the command >plot(name(:,3)*(pi/180),name(:,5))

  8. Use >grid on command at the prompt to see the data with horizontal and vertical gridlines.
  9. If you want to see some particular region of the data more closely, use the command
  10. >axis([x1 x2 y1 y2])

    where

    x1 is the lower limit on the x axis.

    x2 is the upper limit on the x axis.

    y1 is the lower limit on the y axis.

    y2 is the lower limit on the y axis.

  11. To find the slope of the line in the linear region.

a) Open the data file for data editing.

b) Remove the portion which you think is having a non-linear relationship between the variables that have to be plotted.

c)’Save’ the file as name2.txt

d)load the data file name2.txt using

>load name2.txt

d)Use the command

>plot(name(:,3),name(:,5))

to check if the plot shows a linear relationship between the values.

e)Now use the following commands to find the slope of the plot.

>X=name2( :,3)

>Y=name2(:,5)

>[K C]=polyfit(X,Y,1)

After the last command you see two numbers, lets say

K C

The last command assumes a linear relationship between X and Y values i.e. Y=KX+C. and then gives the value of K and C.


Hints for plotting the data in Microsoft Excel

  1. Download the data file.
  2. The data file is in text format. Open the data file for editing and remove all the text at the beginning of file. You can also remove the text later in Excel. Save the file using the ‘Save as’ option as name.txt. Make sure that you do not overwrite the original file since you need the header information for data reduction at a later stage.
  3. Open the Microsoft Excel program window.
  4. Open the file name.txt from the file menu. When you click the open tab, excel gives you several options which can be confusing. So follow these instructions carefully

    a) When you click on the open tab, Excel automatically starts the ‘Text Import Wizard’. Click the ‘Delimited’ option in the file type. In ‘Start import at row’ make the value 1 and click ‘Windows ANSI’ in the file origin window. (the last 2 are default options most of the times). Click on the ‘Next’ tab.

    b) In the Delimiters option, check ‘tab’ and ‘Space’ options. In ‘Text qualifier’ box "(double inverted commas) should be chosen as the option. Click the ‘Next’ tab.

    c) Click ‘Finish’ tab.

 

5. Now (let’s say) to plot column 3 vs. column 4.

    a) Click on the ‘C’ tab. This highlights the third column. Now press the ‘Control’ key on the keyboard and click on the ‘D’ tab. Now you have column 3 and 4 highlighted.

    b) Now open the ‘Insert’ tab on the menu and click on the ‘Chart’. This opens the ‘Chart Wizard’.

    c) In the ‘Standard Type’ menu, click on the ‘XY(Scatter)’.In the ‘Chart sub-type’ click on any option except which shows only the points. Click the ‘Next’ tab.

    d) The ‘Chart Wizard’ now shows the ‘Data’ and ‘Series’ tab. Click the ‘Series’ tab and fill in the name as ‘Plot of 3 vs. 4’ .Click the ‘Next’ tab.

    e)In the ‘Chart Options’ menu, you can label the axes, add gridlines etc. In the ‘Legend’ menu you can specify if you want to see legend on the chart by checking/unchecking the ‘Show legend’ option. Click the ‘Finish’ tab.

6.To find the slope of the line in the linear region.

a) Remove the portion which you think has a non-linear relationship between the variables that have to be plotted. Plot the new data.

b) Click on the plot to highlight it.

c) Go to the ‘Chart’ menu and click on the ‘Add Trendline’ option. This opens the ‘Add Trendline’ window.

d) In the ‘Type’ menu choose ‘Linear’ option.

e) Click the ‘Options’ tab in the window .Check the ‘Display equation on chart’ option and click ‘OK’. This plots a linear fit and gives the slope and the offset of the fit.

Note: Sometimes, Microsoft Excel decides on the format of the values on axis and the limits of the axis automatically. This may lead to confusion and poor graphs. For e.g. it can write numbers (‘0, 25, 50’) as (0.00e00, 2.50e01, 5.00e01). But you can choose your own limits and format of values. To do this, click on the ‘X’ or the ‘Y’ axis of the chart. This opens the ‘Format Axis window. You can change the limits of the axis by going to ‘Scale’ menu and filling in your own limits. Go to the ‘Number’ menu and choose the format of values which you like to be displayed on the graph.