The problems below are designed to introduce work with MATLAB and to do some bas
ID: 1714888 • Letter: T
Question
The problems below are designed to introduce work with MATLAB and to do some basic data manipulation and simple programming. The data in the file “ppt.dat” are precipitation in mm for the Southern Piedmont of the U.S. (Karl et al. 1994). The rows represent years from 1960 through 1989, and the columns represent months from January to December.
Solve the following five problems and turn in all MATLAB files and needed figures.
Additional requirement:
(1) Plot the results of Problems 2 – 4 in one figure. (tip: use “subplot” to divide a figure into multiple panels)
(2) Plot the results of Problems 5 – 6 in another figure. (tip: use “figure” to open new figure window)
(3) For the plot of Problem 3, use “axis” to specify the minimum and maximum of xaxis as [0 13] and use “set” to specify x-axis tick-mark locations at even numbers (e.g., 0, 2, 4, 6, …)
(4) Comment on each line of the M-file of problem 6
1. Read the data into MATLAB.
2. Calculate the total annual ppt for each year and plot these data versus year. (Hint: use the MATLAB help facility to check on the sum command. Recall that you can perform operations on the transpose of a matrix.)
3. Calculate the mean monthly ppt for each month and plot the values using a bar chart. (Hint: check on the mean and bar commands.) Plot the monthly means on a regular plot along with "error bars" showing the standard deviations of the monthly means. (Hint: check the errorbar command and the std command.) How different are the means and medians? Hint: check the median command.)
4. Plot all monthly precipitation values consecutively. (You may want to examine the reshape command.) Is a seasonal pattern evident in the data?
5. Write an m-file program to: (a) query for a year (see the input command); (b) for the selected year, calculate and display the minimum, maximum, and mean monthy precipitation (see the min and max commands); (c) make a stem plot of the data (see the stem command), labelling the axes and placing an appropriate title (see the xlabel, ylabel and title commands).
6. Write a function file that accepts an N × M matrix (such as the precipitation file) as an argument, finds the maximum correlation coefficient (absolute value) between any two columns of the data, reports that value as output, and presents a scatter plot of the two columns of data with maximal correlation. Apply the code to the precipitation file and briefly comment on any interpretation of the result. (You may want to use corrcoef and eye.)
JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC 133.8 157.6 120.9 84.5 87.5 71.3 130.0 112.7 100.1 55.2 28.0 48.1 70.4 153.6 115.7 136.7 91.7 143.1 96.4 159.4 35.6 44.8 54.2 127.1 139.2 100.0 124.7 94.4 63.3 136.0 96.4 77.0 121.5 35.6 130.1 73.1 92.0 78.5 127.1 69.3 80.2 106.5 87.5 53.9 114.0 4.7 135.7 70.3 142.7 125.5 129.5 118.6 51.9 90.1 170.1 166.0 84.4 178.4 49.6 111.8 48.9 104.7 159.1 81.7 46.6 157.4 151.6 89.5 68.2 64.3 44.1 15.8 130.5 109.0 69.8 67.7 116.2 75.6 77.5 94.7 130.9 74.9 40.1 78.5 62.5 86.9 67.3 55.3 127.3 73.8 115.7 176.8 64.2 40.4 68.0 123.0 111.9 19.4 79.4 68.4 107.9 125.4 138.9 69.0 34.3 92.6 107.1 69.3 64.8 84.8 103.6 112.5 84.8 107.2 120.5 123.6 105.2 37.6 37.1 114.4 58.5 79.4 121.5 66.6 75.9 67.9 136.5 140.7 50.1 125.8 63.6 75.3 100.1 116.5 133.8 73.8 153.0 87.5 147.7 137.7 108.9 171.9 69.5 43.7 107.8 108.1 75.3 58.0 145.9 181.2 117.4 86.1 84.0 89.2 125.7 140.2 97.9 114.1 144.2 126.6 109.0 172.1 85.7 101.5 72.9 60.5 27.9 146.6 122.4 90.2 78.6 66.4 126.9 91.1 91.4 139.6 121.0 14.4 61.5 132.5 137.9 108.9 185.7 66.0 141.0 90.3 213.7 71.7 182.5 58.7 71.6 94.5 84.0 36.5 98.0 24.2 146.3 144.2 85.4 66.2 116.3 184.6 77.2 107.6 68.3 31.9 145.1 52.5 60.7 84.0 54.8 114.9 111.8 134.6 103.4 89.7 199.0 22.2 111.0 101.5 116.5 95.6 140.7 116.0 54.9 28.9 75.8 76.3 148.8 157.4 84.4 134.4 116.3 131.2 95.9 93.8 208.8 77.9 109.4 35.6 120.7 42.6 211.3 68.3 86.3 80.3 82.5 53.5 128.2 88.4 72.6 29.9 17.1 98.0 58.5 45.2 75.9 102.4 146.0 123.2 72.5 82.8 24.0 139.6 120.3 131.1 57.3 114.4 93.7 170.0 118.4 93.9 67.0 88.2 74.0 106.4 68.4 126.5 176.7 147.2 81.6 79.2 51.5 79.7 77.2 98.0 119.4 172.8 95.1 137.5 148.7 119.5 142.1 62.9 207.8 113.0 19.7 57.0 52.4 49.2 92.4 124.4 26.5 28.9 104.3 85.5 158.1 166.1 17.3 115.3 213.2 31.9 33.8 50.3 67.4 28.7 67.8 36.4 83.5 192.1 35.7 85.7 118.2 101.6 153.5 98.3 117.9 107.2 56.3 116.3 73.7 75.8 193.0 32.1 98.2 70.5 85.7 44.5 60.7 71.7 86.7 73.2 102.7 109.1 109.3 74.1 96.7 22.2 53.6 112.3 131.4 102.9 135.7 172.8 178.8 99.6 131.1 121.9 71.1 80.3Explanation / Answer
clc,
clear all
close all
load('ppt.dat');
for i = 1:30
A(:,i) = 1959+i;
B(i,:) = sum(ppt(i,:));
c(i,:) = mean(ppt(i,:));
end
for j = 1:30
A(:,j)
B(j,:)
plot(A(:,j),B(j,:))
hold on
plot(A(:,j),c(j,:))
hold on
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.