MAT2409 Assignment 1: MATLAB Analysis of Toowoomba Weather Data
VerifiedAdded on 2023/04/25
|17
|2055
|184
Homework Assignment
AI Summary
This MATLAB assignment solution involves reading meteorological data from CSV files, performing statistical analysis, and visualizing the data. The solution includes functions to read the data, calculate averages and standard deviations, identify missing values, and determine the maximum and minimum temperatures. It also calculates the temperature differences between 9 AM and 3 PM, generates plots, and summarizes key findings in a single line. The assignment covers data processing, statistical analysis, and data visualization techniques using MATLAB, applied to weather data from Toowoomba across different years. This document is available on Desklib, a platform offering a wide range of academic resources including past papers and solved assignments.

Running head: MAT2409 ASSIGNMENT 1
MAT2409 ASSIGNMENT 1
Name of the Student
Name of the University
Author Note
MAT2409 ASSIGNMENT 1
Name of the Student
Name of the University
Author Note
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

1Assignment 5
Question 1:
The meteorological data collected by ABM is given in the 4 .csv file which contains the
following variables as column headers.
Day of month = 1st column
Minimum temperature (°C) = 2nd column
Maximum temperature (°C) = 3rd column
Rainfall in mm = 4th column
9 AM temperature (°C) = 5th column
3 PM temperature (°C) = 6th column
Now, a MATLAB function is created which takes input the filename and the number of rows
or lines to skip for column heading and displays an array with numeric value from the file. If
the file contain NAN values that is the missing values then those are automatically replaced
by 0.
MATLAB function:
function filemat = readcsvfile(filename,lines)
% filename = name of the file with its dot format
% lines = number of rows to skip for column header
filemat = xlsread(filename);
filemat([lines-1,lines],:) = [];
end
Question 1:
The meteorological data collected by ABM is given in the 4 .csv file which contains the
following variables as column headers.
Day of month = 1st column
Minimum temperature (°C) = 2nd column
Maximum temperature (°C) = 3rd column
Rainfall in mm = 4th column
9 AM temperature (°C) = 5th column
3 PM temperature (°C) = 6th column
Now, a MATLAB function is created which takes input the filename and the number of rows
or lines to skip for column heading and displays an array with numeric value from the file. If
the file contain NAN values that is the missing values then those are automatically replaced
by 0.
MATLAB function:
function filemat = readcsvfile(filename,lines)
% filename = name of the file with its dot format
% lines = number of rows to skip for column header
filemat = xlsread(filename);
filemat([lines-1,lines],:) = [];
end

2Assignment 5
Sample run and Output:
>> filename = '3142138_1682136058_Toowoomba201301.csv';
>> lines = 2;
>> filemat = readcsvfile(filename,lines);
>> filemat
filemat =
1.0000 16.7000 26.7000 0 21.4000 26.2000
2.0000 16.6000 33.7000 0 25.5000 33.5000
3.0000 18.2000 29.3000 0 22.9000 28.2000
4.0000 16.7000 28.2000 0 21.6000 27.0000
5.0000 16.9000 26.6000 0 22.4000 25.7000
6.0000 17.7000 25.6000 0 21.6000 24.0000
7.0000 17.3000 27.8000 0 20.8000 25.8000
8.0000 17.6000 NaN 0.2000 21.4000 29.3000
9.0000 17.3000 34.4000 0 25.9000 33.5000
10.0000 20.6000 34.2000 1.8000 26.0000 32.9000
11.0000 17.9000 32.2000 65.8000 24.7000 31.4000
12.0000 20.9000 34.4000 0 26.4000 33.3000
13.0000 21.1000 35.1000 0 26.5000 33.7000
Sample run and Output:
>> filename = '3142138_1682136058_Toowoomba201301.csv';
>> lines = 2;
>> filemat = readcsvfile(filename,lines);
>> filemat
filemat =
1.0000 16.7000 26.7000 0 21.4000 26.2000
2.0000 16.6000 33.7000 0 25.5000 33.5000
3.0000 18.2000 29.3000 0 22.9000 28.2000
4.0000 16.7000 28.2000 0 21.6000 27.0000
5.0000 16.9000 26.6000 0 22.4000 25.7000
6.0000 17.7000 25.6000 0 21.6000 24.0000
7.0000 17.3000 27.8000 0 20.8000 25.8000
8.0000 17.6000 NaN 0.2000 21.4000 29.3000
9.0000 17.3000 34.4000 0 25.9000 33.5000
10.0000 20.6000 34.2000 1.8000 26.0000 32.9000
11.0000 17.9000 32.2000 65.8000 24.7000 31.4000
12.0000 20.9000 34.4000 0 26.4000 33.3000
13.0000 21.1000 35.1000 0 26.5000 33.7000
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

3Assignment 5
14.0000 23.0000 28.9000 0 26.9000 25.5000
15.0000 16.0000 25.3000 0 19.1000 24.1000
16.0000 16.5000 28.3000 0 21.6000 27.9000
17.0000 16.6000 30.1000 0 22.7000 29.5000
18.0000 17.3000 33.7000 0 23.7000 28.9000
19.0000 19.5000 35.1000 0 25.8000 32.9000
20.0000 19.8000 30.2000 2.6000 22.4000 29.2000
21.0000 18.5000 26.9000 0.6000 19.9000 25.0000
22.0000 18.4000 28.5000 1.2000 21.1000 27.3000
23.0000 18.8000 30.2000 0 23.3000 29.3000
24.0000 18.7000 21.9000 NaN 20.3000 20.6000
25.0000 18.5000 22.2000 16.0000 19.9000 21.0000
26.0000 19.5000 21.5000 43.8000 20.9000 20.7000
27.0000 19.4000 21.4000 142.8000 19.7000 19.5000
28.0000 19.4000 26.2000 141.2000 21.4000 22.6000
29.0000 19.4000 27.5000 33.6000 22.1000 23.7000
30.0000 19.5000 29.3000 0 21.8000 26.6000
31.0000 19.5000 28.5000 0 21.0000 26.1000
14.0000 23.0000 28.9000 0 26.9000 25.5000
15.0000 16.0000 25.3000 0 19.1000 24.1000
16.0000 16.5000 28.3000 0 21.6000 27.9000
17.0000 16.6000 30.1000 0 22.7000 29.5000
18.0000 17.3000 33.7000 0 23.7000 28.9000
19.0000 19.5000 35.1000 0 25.8000 32.9000
20.0000 19.8000 30.2000 2.6000 22.4000 29.2000
21.0000 18.5000 26.9000 0.6000 19.9000 25.0000
22.0000 18.4000 28.5000 1.2000 21.1000 27.3000
23.0000 18.8000 30.2000 0 23.3000 29.3000
24.0000 18.7000 21.9000 NaN 20.3000 20.6000
25.0000 18.5000 22.2000 16.0000 19.9000 21.0000
26.0000 19.5000 21.5000 43.8000 20.9000 20.7000
27.0000 19.4000 21.4000 142.8000 19.7000 19.5000
28.0000 19.4000 26.2000 141.2000 21.4000 22.6000
29.0000 19.4000 27.5000 33.6000 22.1000 23.7000
30.0000 19.5000 29.3000 0 21.8000 26.6000
31.0000 19.5000 28.5000 0 21.0000 26.1000
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

4Assignment 5
Question 2:
Now, the averages of column or variable and their minimum and maximum values along with
total number of missing values of the output of task 1 matrix is calculated by the following
MATLAB function.
MATLAB function:
function [ave_std,total_rain,no_miss,max_min] = averageandsummary(filemat)
% assigning names to columns
mintemp = filemat(:,2);
maxtemp = filemat(:,3);
rainfall = filemat(:,4);
temp9am = filemat(:,5);
temp3pm = filemat(:,6);
% finding missing values
no_miss = sum(sum(isnan(filemat)));
% calculating averages
avgmintemp = nanmean(mintemp);
avgmaxtemp = nanmean(maxtemp);
avgrainfall= nanmean(rainfall);
Question 2:
Now, the averages of column or variable and their minimum and maximum values along with
total number of missing values of the output of task 1 matrix is calculated by the following
MATLAB function.
MATLAB function:
function [ave_std,total_rain,no_miss,max_min] = averageandsummary(filemat)
% assigning names to columns
mintemp = filemat(:,2);
maxtemp = filemat(:,3);
rainfall = filemat(:,4);
temp9am = filemat(:,5);
temp3pm = filemat(:,6);
% finding missing values
no_miss = sum(sum(isnan(filemat)));
% calculating averages
avgmintemp = nanmean(mintemp);
avgmaxtemp = nanmean(maxtemp);
avgrainfall= nanmean(rainfall);

5Assignment 5
avgtemp9am= nanmean(temp9am);
avgtemp3pm = nanmean(temp3pm);
% calculating standard deviations
stdmintemp = nanstd(mintemp);
stdmaxtemp = nanstd(maxtemp);
stdrainfall= nanstd(rainfall);
stdtemp9am= nanstd(temp9am);
stdtemp3pm = nanstd(temp3pm);
% assigning values in a string matrix
ave_std =
[string('property'),string('mintemp'),string('maxtemp'),string('rainfall'),string('temp9am'),strin
g('temp3pm');string('Average'),avgmintemp,avgmaxtemp,avgrainfall,avgtemp9am,avgtemp3
pm;...
string('Stddev'),stdmintemp,stdmaxtemp,stdrainfall,stdtemp9am,stdtemp3pm];
% calculating total rainfall
total_rain = nansum(rainfall);
avgtemp9am= nanmean(temp9am);
avgtemp3pm = nanmean(temp3pm);
% calculating standard deviations
stdmintemp = nanstd(mintemp);
stdmaxtemp = nanstd(maxtemp);
stdrainfall= nanstd(rainfall);
stdtemp9am= nanstd(temp9am);
stdtemp3pm = nanstd(temp3pm);
% assigning values in a string matrix
ave_std =
[string('property'),string('mintemp'),string('maxtemp'),string('rainfall'),string('temp9am'),strin
g('temp3pm');string('Average'),avgmintemp,avgmaxtemp,avgrainfall,avgtemp9am,avgtemp3
pm;...
string('Stddev'),stdmintemp,stdmaxtemp,stdrainfall,stdtemp9am,stdtemp3pm];
% calculating total rainfall
total_rain = nansum(rainfall);
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

6Assignment 5
% calculating maximum and minimum values of temperature in a month
max_min = ["maximum temp","minimum temp";nanmax(maxtemp),nanmin(mintemp)];
end
Sample run for output of file 3142138_1682136058_Toowoomba201301.csv and output:
[ave_std,total_rain,no_miss,max_min] = averageandsummary(filemat)
ave_std =
3×6 string array
"property" "mintemp" "maxtemp" "rainfall" "temp9am" "temp3pm"
"Average" "18.5097" "28.7967" "14.9867" "22.6032" "27.2548"
"Stddev" "1.6142" "4.0759" "37.7086" "2.2746" "4.1441"
total_rain =
449.6000
no_miss =
2
max_min =
2×2 string array
"maximum temp" "minimum temp"
% calculating maximum and minimum values of temperature in a month
max_min = ["maximum temp","minimum temp";nanmax(maxtemp),nanmin(mintemp)];
end
Sample run for output of file 3142138_1682136058_Toowoomba201301.csv and output:
[ave_std,total_rain,no_miss,max_min] = averageandsummary(filemat)
ave_std =
3×6 string array
"property" "mintemp" "maxtemp" "rainfall" "temp9am" "temp3pm"
"Average" "18.5097" "28.7967" "14.9867" "22.6032" "27.2548"
"Stddev" "1.6142" "4.0759" "37.7086" "2.2746" "4.1441"
total_rain =
449.6000
no_miss =
2
max_min =
2×2 string array
"maximum temp" "minimum temp"
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

7Assignment 5
"35.1" "16"
Question 3:
Now, this function calculates the differences between the 9 Am and 3 pm temperatures and
minimum and maximum of differences and also generates a plot according to question.
MATLAB function:
function [diff39,d_max,d_min] = differences(filemat)
% assigning names to columns
day = filemat(:,1);
temp9am = filemat(:,5);
temp3pm = filemat(:,6);
% replacing nan values with 0s in both temperature columns
for i=1:length(temp9am)
if isnan(temp9am(i)) == 1
temp9am(i) = 0;
end
end
for i=1:length(temp3pm)
if isnan(temp3pm(i)) == 1
temp3pm(i) = 0;
end
end
diff39 = temp9am - temp3pm; % difference of 9 am and 3 pm temperature
plot(day,diff39)
xlim([1,31])
xlabel('day number in month')
ylabel('difference of 9 Am and 3 pm temperature in degree C')
title('9 Am - 3 pm temperature in degree celcius')
"35.1" "16"
Question 3:
Now, this function calculates the differences between the 9 Am and 3 pm temperatures and
minimum and maximum of differences and also generates a plot according to question.
MATLAB function:
function [diff39,d_max,d_min] = differences(filemat)
% assigning names to columns
day = filemat(:,1);
temp9am = filemat(:,5);
temp3pm = filemat(:,6);
% replacing nan values with 0s in both temperature columns
for i=1:length(temp9am)
if isnan(temp9am(i)) == 1
temp9am(i) = 0;
end
end
for i=1:length(temp3pm)
if isnan(temp3pm(i)) == 1
temp3pm(i) = 0;
end
end
diff39 = temp9am - temp3pm; % difference of 9 am and 3 pm temperature
plot(day,diff39)
xlim([1,31])
xlabel('day number in month')
ylabel('difference of 9 Am and 3 pm temperature in degree C')
title('9 Am - 3 pm temperature in degree celcius')

8Assignment 5
d_max = max(abs(diff39)); % maximum absolute difference
d_min = min(abs(diff39)); % minimum absolute difference
Output:
[diff39,d_max,d_min] = differences(filemat)
diff39 =
-4.8000
-8.0000
-5.3000
-5.4000
-3.3000
-2.4000
-5.0000
-7.9000
-7.6000
-6.9000
-6.7000
-6.9000
-7.2000
1.4000
-5.0000
-6.3000
-6.8000
-5.2000
-7.1000
-6.8000
-5.1000
-6.2000
d_max = max(abs(diff39)); % maximum absolute difference
d_min = min(abs(diff39)); % minimum absolute difference
Output:
[diff39,d_max,d_min] = differences(filemat)
diff39 =
-4.8000
-8.0000
-5.3000
-5.4000
-3.3000
-2.4000
-5.0000
-7.9000
-7.6000
-6.9000
-6.7000
-6.9000
-7.2000
1.4000
-5.0000
-6.3000
-6.8000
-5.2000
-7.1000
-6.8000
-5.1000
-6.2000
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

9Assignment 5
-6.0000
-0.3000
-1.1000
0.2000
0.2000
-1.2000
-1.6000
-4.8000
-5.1000
d_max =
8
d_min =
0.2000
Plot:
-6.0000
-0.3000
-1.1000
0.2000
0.2000
-1.2000
-1.6000
-4.8000
-5.1000
d_max =
8
d_min =
0.2000
Plot:
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

10Assignment 5
5 10 15 20 25 30
day number in month
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
difference of 9 Am and 3 pm temperature in degree C 9 Am - 3 pm temperature in degree celcius
Question 4:
Now, summary of all critical information from Question 2 and Question 3 are gathered and
displayed in a single line by the following MATLAB function. The function takes the output
of task 2 and task 3 as inputs.
MATLAB function:
function allsummary(total_rain,no_miss,max_min,d_max,d_min)
sprintf('Total rainfall in month = %g mm. Total missing values = %g. Maximum temperaure
= %g degree C. Minimum temperature = %g. Maximum difference = %g degree C. Minimum
difference = %g degree C.',...
total_rain,no_miss,str2double(max_min(2,1)),str2double(max_min(2,2)),d_max,d_min)
end
Output:
allsummary(total_rain,no_miss,max_min,d_max,d_min)
5 10 15 20 25 30
day number in month
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
difference of 9 Am and 3 pm temperature in degree C 9 Am - 3 pm temperature in degree celcius
Question 4:
Now, summary of all critical information from Question 2 and Question 3 are gathered and
displayed in a single line by the following MATLAB function. The function takes the output
of task 2 and task 3 as inputs.
MATLAB function:
function allsummary(total_rain,no_miss,max_min,d_max,d_min)
sprintf('Total rainfall in month = %g mm. Total missing values = %g. Maximum temperaure
= %g degree C. Minimum temperature = %g. Maximum difference = %g degree C. Minimum
difference = %g degree C.',...
total_rain,no_miss,str2double(max_min(2,1)),str2double(max_min(2,2)),d_max,d_min)
end
Output:
allsummary(total_rain,no_miss,max_min,d_max,d_min)

11Assignment 5
ans =
'Total rainfall in month = 449.6 mm. Total missing values = 2. Maximum temperaure =
35.1 degree C. Minimum temperature = 16. Maximum difference = 8 degree C. Minimum
difference = 0.2 degree C.'
Question 5:
Now, a MATLAB script is written which does all the operations of task 2, 3 and 4 for all the
four January data files for Toowoomba attached with question.
MATLAB script:
% performing operations for 3142137_2068960719_Toowoomba201201.csv file
filename = '3142137_2068960719_Toowoomba201201.csv';
lines = 1;
filemat = xlsread(filename);
[ave_std,total_rain,no_miss,max_min] = averageandsummary(filemat);
figure(1)
[diff39,d_max,d_min] = differences(filemat);
allsummary(total_rain,no_miss,max_min,d_max,d_min)
ans =
'Total rainfall in month = 449.6 mm. Total missing values = 2. Maximum temperaure =
35.1 degree C. Minimum temperature = 16. Maximum difference = 8 degree C. Minimum
difference = 0.2 degree C.'
Question 5:
Now, a MATLAB script is written which does all the operations of task 2, 3 and 4 for all the
four January data files for Toowoomba attached with question.
MATLAB script:
% performing operations for 3142137_2068960719_Toowoomba201201.csv file
filename = '3142137_2068960719_Toowoomba201201.csv';
lines = 1;
filemat = xlsread(filename);
[ave_std,total_rain,no_miss,max_min] = averageandsummary(filemat);
figure(1)
[diff39,d_max,d_min] = differences(filemat);
allsummary(total_rain,no_miss,max_min,d_max,d_min)
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 17

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.