Math 171 - Alexiades
                          Lab 4
                Reading data files

1. Reading data from a file for plotting and exploration :
  Given a (plain text!) file containing N columns of values, we need to read the values into matlab for exploration and plotting.
  To do this, we need to know the name of the file, and how data is arranged in it, so need to open it in a (plain text!) editor.
  Write a script "read.m" which:
  • reads a given file "file.dat" into a matrix "mat",
  • extracts the columns from "mat" into arrays "c1", "c2", ..., "cN",
  • plots some column versus another column, with a title, and labeled axes.
    To test and debug your code, create a "file.dat" with N=2 columns, each with 3 values ( so a 3×2 matrix ).
    The first column should be sorted. You can just enter some numbers in "file.dat" in an editor.
    Next, test it on a 4×3 array to make sure it also works. Insert brief comments to document what is being done.

    To apply this on real data, I am providing a data file, produced by a code that implements a mathematical model for
    bacterial chemotaxis (by numerical solution of a system of Partial Differential Equations).
    It contains profiles (values at a grid of locations x(i) at some particular time) of several quantities,
    labeled by column at the top ( x(i)   C(i)   B(i)  etc). The last column is the index "i" of x(i).
    Of main interest is the 3rd column, labeled "B(i)". It represents bacterial density at location x(i), at the output time
    (normalized, B(i) means B(i)×109/mL). It has a "bump", and want to find its FWHM, i.e. the width of the interval [xLeft, xRight]
    at half-maximum height. Biologically, this is the width of the "band" the bacteria form during chemotaxis.

    2. To do:  
      Download the file prof300s.dat and save it as "prof300s.dat" . View it in an editor to see its contents.
      The first two lines contain labels, need to be read over with fgetl .
      The rest of the lines are numerical values to be scanned into a matrix, say "mat".
    You can see what the B-profile looks like easily in gnuplot:   gnuplot>   plot "prof300s.dat" u 1:3 w lines lw 2

    Copy your "read.m" to "Lab4.m" and modify appropriately to achieve the following:
      a. Read the data into a matrix "mat".
      b. Extract each column into a vector (with sensible names: x , C , B , ... ). Only need x and B, so may extract only those.
      c. Find Bmax = maximum value of B, and at which index it occurs, iBmax. Set cut = Bmax/2 .
      d. Plot B vs x and the line at height cut, on the same plot. Try to do it in Matlab.
        The units of x are micrometers (μm).
        Note: Once you know the value of "cut", say 1.5, it's easy to do it in Gnuplot (outside Matlab):
              gnuplot>  cut=1.5;  plot "prof300s.dat" u 1:3 w lines lw 2 , cut lw 3
      e. Is this value of cut a good choice here? does it really represent half-maximum of the bump ?
        (note that the "base" value of B is 1, not zero). Figure out a better expression for setting "cut".
      f. Make sure your code runs and produces the plot.

    ( In the next lab, you'll incorporate finding FWHM into your code, see HW assignment. )

    3. Prepare Lab4.m for submission:
  • At the top of your Lab4.m code, insert % Name, Date, Lab4
  • At the end of the code insert a separator:   %=====================================%
  • Publish it in Matlab. Check the PDF to make sure it contains the output.

    Then submit it via Canvas by the deadline.