In: Mechanical Engineering
Get the avehighs.txt file from BB. The file contains monthly average temperatures from three different locations. The location ID is in the first column and monhtly average temperatures are in the next 12 columns. Write a script that will:
data from file
avehighs
432 33 37 42 45 53 72 82 79 66 55 46 41 777 29 33 41 46 52 66 77 88 68 55 48 39 567 55 62 68 72 75 79 83 89 85 80 77 65
1. load the data
2. call a function that will (a) plot the data on a column of subplots (b) place an x label, months, on the last plot (c) place a ylabel,Monthly Avg Temp (F), on the second plot, (d) for a bonus put a legend on each plot that indicates the location id, and (e) return the yearly average temperatures and the location ID as three two element vectors
3. Display the average yearly temp for each location.
% MATLAB script is as follows
% Function
function [ avgt ayt ] = temperature( A )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
month=1:12;
subplot(3,1,1)
plot(month,A(1,(2:end)))
legend('432')
subplot(3,1,2)
plot(month,A(2,(2:end)))
ylabel('Monthly Avg Temp (F)')
legend('777')
subplot(3,1,3)
plot(month,A(2,(2:end)))
xlabel('months')
legend('567')
avgt=[432 mean(A(1,(2:end))); 777 mean(A(2,(2:end))); 567 mean(A(3,(2:end)));]; %yearly average temperatures and the location ID as three two element vectors
ayt= avgt(:,2); %average yearly temp for each location
end
% MATLAB script
clear all
clc
A= importdata('avehighs.txt');
[ avgt ayt ] = temperature( A )
% Results