CS 150 - Assignment 10 - Matlab

Due: Wednesday 5/10 at the beginning of class

For our final lab, we're going to be adding some additional functionality to our weather program from Lab 8. The goal of Lab 8 was to write a program that could collect weather data over time. Once you have this data, the next step is to analyze it! This lab explores this data analysis using Matlab.

You may (and are encourage to) work with a partner on this lab.

Saving your work

We recommend storing your files on our department server "basin" for this lab. See the instructions for connecting to basin, which are also linked from the main course page. Follow the instructions for Windows users to map a network drive from your virtual Matlab session. Unfortunately, you'll have to do this again each time you log on. Once you have a network drive, say Z:, you can access it from Matlab by clicking on the little arrow to the left of the drive letter (C:) above the folder pane.

Function recap

Just to make sure everyone is clear, here is a quick review of defining functions in Matlab:

Weather data

Reading and writing from files in Matlab can be done easily if the data is represented in the file in a matrix-like format. I have posted two -matrix files that can be read easily using dlmread in Matlab here:
Download the datafiles
Each line in the -matrix file has 24 temperature readings separated by a space representing hourly temperature readings for one day. Download both of these files into your working folder for this lab. Make sure you understand what the data in the files represents.

Visualizing the data

In Matlab, write a function called plot_weather that takes a matrix of weather data as a parameter and then plots the average, maximum and minimum temperature for each day in the data. Your plot should include appropriate labels for the x and y axis and should also include a legend. The input matrix will be in the same format as the data file, with each row having 24 entries and each row representing a day.

For example, to generate a plot of the test data you would type:

>> test_data = dlmread('test-matrix.txt');
>> plot_weather(test_data)
and the results should look something like:

A few hints:

When you've got it working, try plotting the weather data from Wisconsin (e.g. wisc-matrix.txt). The data should look much more interesting since it's real data! Can you figure out around what time the data set starts and ends?

Save a copy of the plot of the Wisconsin data and submit it along with your code. To save the plot, click on the "Save" button (it looks like a disk) in the plot window. Under file type, select ".png".

Analyzing the data

Plotting the data allows us to analyze some aspects of the data, but there are many interesting additional questions that we could also ask. Write a Matlab function called weather_stats that takes a matrix of weather data as a parameter and displays the following information about the weather data: In writing this function: For example, the output from this function on the data from the test file would be:
Days in data set:
     3

Average temperature:
   42.7853

Coldest temperature:
   25.1900

Hottest temperature:
  101.1100

Average temperature fluctuation:
   28.2867

Number of days above 80:
     1

Number of days below 32
     1

Number of days were it didn't get above freezing:
     0

Average temperature when temps got below 32:
   28.5592
A few hints:

Extra points

You may earn up to 2 extra points on this assignment. Below are some ideas, but you may incorporate your own if you'd like. Make sure to document your extra point additions in comments at the top of the file.

When you're done

Make sure that your program is properly commented. For Matlab this means: In addition, make sure that you've used good style. For Matlab this includes avoiding using for loops.

What to submit

To submit multiple files, put all your files inside a new directory and then create a .zip file from this directory. On the Macs, right-click on the directory and select "Compress...". If you're working on Windows, right-click on the file and select "Send to" then select "Compressed (zipped) Folder" (or if you don't have this option, use Winzip). You will then see a file with a .zip extension be created.

Submit this .zip file digitally at the usual location.

Grading

                                 Points
plot weather
    generates appropriate plot   4
    legend and labels            1
weather stats
    days                         1
    avg. temp                    1
    coldest temp                 1
    hottest temp                 1
    avg. temp fluctuation        1
    days above 80 and below 32   2
    days not above freezing      2
    average temp when below 32   2
    extra function               1

Comments, style                  5
Prelab                           1
Extra points                     2

total                           23 + 2