The left column is day of the year (1 through 365).
The top row is year (1961-2000).
If the number in an element is positive, that means that it rained and the number is the amount of rainfall (inches).
If the number is 0 or negative, that means that there was no rain and that the negative number was the amount of evaporation that occurred.
Here is the Excel file that contains these data.
Here is your assignment:
Write a MatLab program that
Reads this Excel file (put it in a matrix called "M")
Totals the amount of precipitation for each year (first 1961, then 1962, etc.; only + numbers are precipitation).
Counts the number of rainly days (days having precipitation)
Calculates the average magnitude of the precipitation for that year (totalP/cnt).
Create a matrix (3x40)
The first row in the matrix for each column is the total P (Data( 1, j ), if your matrix is called Data and j is the index for your columns)
The second row is number of rainy days (Data( 2, j ), if your matrix is called Data and j is the index for your columns)
The third row is the average amount of precipitation in a storm for that year (Data( 3, j ), if your matrix is called Data and j is the index for your columns)
Write your data matrix to a new Excel file
xlswrite(filename, matrix) is the general form.
If your new matrix is called Data and your want your Excel file to be called newdata it would be

xlswrite('newdata', Data)

Do this for every year in the data set (remember that the data starts in row 2, column 2, for 1961 (i.e., M(2,2)) and that each year has 365 days (so 1961 goes from M(2,2) to M(366,2)).
If you have any trouble reading sv.xlsx, you can also put the file name in a variable and read the variable:
D = 'sv.xlsx'
M = xlsread(D)
You will have to use nested for loops, with rows going from 2 to 366 and colums going from 2 to 41.
Reset TotalP and cnt to zero at the beginning of each year.
Calculate average P after the end of the interior loop (days) and before the end of the outside loop (years).
Extra credit (1 point, could raise a previous quiz by a grade!): Instead of creating a 3 x 40 matrix to contain your data, create a 4 x 40 matrix, with the top line containing the year of the data (1961, 1962, etc.).

Want an answer?

No answer yet. Submit this
question to the community.