In: Computer Science
%% Homework A8_HW % Analyze hurricaine data over 2001-2014 and 2015-2020 time periods.% The data are provided in 2 csv files containing years and number of% hurricaines for each year in sequential order, i.e.,: 2001 4 2002 6 ...% Download the 2 csv files AtlanticHurricanes20012014.csv and% AtlanticHurricanes20152020.csv and place them in the same folder % with your m-fileclearclc% read 2 csv files into 2 arrays hurr1 and hurr2filename = 'AtlanticHurricanes20012014.csv';hurr1 = csvread(filename);filename = 'AtlanticHurricanes20152020.csv';hurr2 = csvread(filename);%% 1.Find and print the number of years in each of the two arrays%% 2. Using "reshape" and "transpose" functions, reshape the two arrays % into 2-column arrays where the first column is the year number, and % the second column is the corresponding number of hurricanes for that year%% 3. Combine the two 2-column arrays into a new single 2-column array hurrAll%% 4. Print the combined array hurrAll using the disp function % (print headings for each column)%% 5. Sort the combined array hurrAll row-by-row based on % the number of hurricanes in ascending order and print the array%% 6. Using "find" function, find the years with minimal and maximal % numbers of hurricanes. Print these years along with respective % hurricaine numbers using "fprintf" function
This is MATLAB and the documents are a single row array as follows: (THIS IS THE INFO NEEDING TO BE SORTED)
hurr1 = 2010 9 2011 8 2012 7 2013 6
hurr2 = 2014 6 2015 7 2016 8 2017 9
clear
clc
filename = 'AtlanticHurricanes20012014.csv';
hurr1 = csvread(filename);
filename = 'AtlanticHurricanes20152020.csv';
hurr2 = csvread(filename);
%for testing
%hurr1 = [2010 9 2011 8 2012 7 2013 6];
%hurr2 = [2014 6 2015 7 2016 8 2017 9];
%% 1.Find and print the number of years in each of the two
arrays
fprintf('Number of years in hurr1: %d\n',length(hurr1)/2);
fprintf('Number of years in hurr2: %d\n',length(hurr2)/2);
%% 2. Using "reshape" and "transpose" functions, reshape the two
arrays % into 2-column arrays where the first column is the year
number,
% and % the second column is the corresponding number of hurricanes
for that year
hurr1=reshape(hurr1,2,4)';
hurr2=reshape(hurr2,2,4)';
%% 3. Combine the two 2-column arrays into a new single 2-column
array hurrAll
hurrAll = [hurr1;hurr2];
%% 4. Print the combined array hurrAll using the disp function %
(print headings for each column)
disp(' Year hurricanes')
disp(hurrAll)
%% 5. Sort the combined array hurrAll row-by-row based on % the
number of hurricanes in ascending order and print the array
hurrAll = sortrows(hurrAll,2);
disp(' Year hurricanes')
disp(hurrAll)
%% 6. Using "find" function, find the years with minimal and
maximal % numbers of hurricanes.
% Print these years along with respective % hurricaine numbers
using "fprintf" function
maxInd = find(hurrAll(:,2)==max(hurrAll(:,2)));
minInd = find(hurrAll(:,2)==min(hurrAll(:,2)));
fprintf('Years with maximum hurricanes\n')
fprintf('year: %d hurricanes: %d\n',hurrAll(maxInd,:)')
fprintf('Years with minimum hurricanes\n')
fprintf('year: %d hurricanes: %d\n',hurrAll(minInd,:)')