Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment will help you understand how for loops can be used to accomplish

ID: 2315220 • Letter: T

Question

This assignment will help you understand how for loops can be used to accomplish tasks that would otherwise require extensive time and would stress Excel’s capabilities. Coding Constraints: You may not use reshape() to solve Part 1 or 2. You must use FOR LOOPs. However, you may use embedded MATLAB syntax to check your answer. PART 1. Reorganize weather station measurements into column format The readings from a weather station in Los Angeles outputs average daily measurements of atmospheric variables. The weather station file WS_2010.txt includes the year, month, day, Temperature [K], Relative Humidity [%], and Surface pressure [Pa], in that order, in one single row. There are 365 days of observation. For example: 2010 1 1 286.90 62.88 101768.180 2010 1 2 286.64 61.62 101746.805 2010 1 3 286.38 61.05 101754.727 2010 1 4 286.41 63.31 101779.648 2010 1 5 286.67 … The numbers above in bold/red are the date values followed by the atmospheric readings. Use FOR LOOP(S) syntax to separate the daily values into a six column matrix. There are several ways to perform this analysis. Save this matrix to a file called “LA_climate_2010_columns.txt”

Explanation / Answer

%clearing window, variables and figures
clear all;
close all;
clf;
clc;
A=csvread('WS_2010.txt');
for i=1:1:6
if i==1
y=A(:,i);
elseif i==2
m=A(:,i);
elseif i==3
d=A(:,i);
elseif i==4
T=A(:,i);
elseif i==5
RH=A(:,i);
else
SP=A(:,i);
end
end
header1 = 'Year';
header2 = 'Month!';
header3 = 'day';
header4 = 'Temperature!';
header5='Relative Humidity';
header6='Surface Pressure';
fid=fopen('LA_climate_2010_columns.txt','w');
fprintf(fid, [ header1 ' ' header2 ' ' header3 ' ' header4 ' ' header5 ' ' header6 ' ']);
fprintf(fid, '%d %d %d %f %f %f ', [y(:) m(:) d(:) T(:) RH(:) SP(:)]');
fclose(fid);
type LA_climate_2010_columns.txt