Sunteți pe pagina 1din 10

WEATHER ANALYSIS PROGRAM

By Seth Cottengim, Dengchai Li, Junyi Lu


INTRODUCTION

► Plots graph of monthly average temperature from 2010-2018.

► Shows the current temperature in your location.

► Recommends what to wear based on the temperature.


SOLVED PROBLEMS

▶ Code – errors, using complex code algorithm etc.

▶ Data sources - weather.com, usclimatedata.com

▶ Establishing the connection between MATLAB and websites.


CODE
% Seth Cottengim, Dengchai Li, Junyi Lu
% ENGR 1412-003
% weather_analysis_003.m

clear; format short; clc; close all;

AvgTemp = zeros(9,12);
for i= 0:1:8
str = [sprintf('https://www.usclimatedata.com/climate/jonesboro/arkansas/united-
states/usar0304/201%d',i)];
for j = 1:12
url = [str sprintf('/%d#history',j)];
[stat,h] = web(url);
code = webread(url);
tree = htmlTree(code);
selector = "td";
subtrees = findElement(tree,selector);
webtext = extractHTMLText(subtrees);

idx = find(strcmp([webtext(:)], 'Average temperature:'));


AvgT = webtext(idx + 1);
AvgT_raw = AvgT(3);
AvgTemp(i+1,j) = strtok(AvgT_raw,'°');
close(h)
end
end
AvgTemp(7,7) = 78.1800
CODE
AvgTemp =
31.6000 32.6000 48.9000 62.2500 70.3000 81.6500 78.9500 83.3500 73.0500 61.5500 48.6500 34.4000
34.1500 40.6000 45.1000 59.7500 47.5000 78.7000 83.7000 80.9000 69.4500 59.1000 51.6000 40.8500
41.5000 40.3500 60.7000 62.3000 62.3500 76.3000 79.2500 73.7500 71.8000 53.4500 45.5000 44.1000
39.0500 39.9500 42.3500 56.2500 63.1500 78.5000 75.3000 73.3000 72.9000 57.6000 42.0000 36.9500
31.4500 34.2500 41.5500 58.5500 69.1500 72.7000 71.2500 78.2500 72.8000 63.5500 38.0500 41.6500
35.4000 29.6000 45.5000 61.6000 64.4000 71.1000 81.2000 75.4500 72.3500 57.0500 52.1000 47.9000
33.9500 42.3000 52.6500 38.6000 65.5000 71.0500 78.1800 48.1500 75.3000 66.1500 50.3000 39.1000
42.0000 46.7000 52.6500 63.1500 62.9000 75.4000 80.2500 73.3000 72.6000 62.3000 48.3500 38.3500
31.9000 42.4500 50.1000 51.6500 74.3000 79.2500 75.5000 72.7500 68.9500 58.8500 43.8500 39.5000

month={'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'};
for k = 1:8
plot(AvgTemp(k,:)); hold on;
end
plot(AvgTemp(9,:)); hold off;
set(gca,'xtick',1:12,'XtickLabel',month)
xlabel('Month');ylabel('Temperature (°F)');
title('Average Temperature per Month'); grid on;
legend('2010','2011','2012','2013','2014','2015','2016','2017','2018');
CODE
url='https://weather.com/weather/today/l/0d96b1be8084eb79834f88c6d6ece8b33c763f73e0103095b448faa85a50901d';
[stat,h] = web(url);
code = webread(url);
tree = htmlTree(code);
selector = "span";
subtrees = findElement(tree,selector);
webtext = extractHTMLText(subtrees);
idx = find(strcmp([webtext(:)], 'Feels Like '));
TempRaw = webtext(idx - 1);
TempToday = strtok(TempRaw,'°');
close(h)

T = str2double(TempToday);
if T < 50
Temp = sprintf('It is %d °F',T);
disp(Temp)
disp('It is cold outside make sure you have a jacket')
elseif 50 <= T && T <= 65
Temp = sprintf('It is %d °F',T);
disp(Temp)
disp('It is cool outside wear a sweatshirt')
else
Temp = sprintf('It is %d °F',T);
disp(Temp)
disp('It is hot outside dress light')
end
RESULT / CONCLUSION

Output Example:
It is 51 °F
It is cool outside wear a sweatshirt

▶ This data can then be compared to the graph created by the


program.
▶ And you will know how to dress for the temperature.
RESULT / CONCLUSION
DISCUSSION

Other possible/similar outcomes:


▶ Pulling data for every day over desired time to see temperature
change.
▶ Allowing user input to request temperature data for specific
locations.
▶ Comparing temperatures in different locations.
▶ Comparing today's temperature to the average temperature of
the month.
REFERENCE

▶ https://www.mathworks.com/help

▶ https://www.usclimatedata.com

▶ https://www.weather.com

S-ar putea să vă placă și