0% found this document useful (0 votes)
32 views5 pages

Homework 5 B

The document contains a homework assignment by Zane Williams, dated November 19, 2020, which includes three problems related to data analysis using MATLAB. Problem 2 involves plotting air and water temperatures from Atlantic City data, Problem 3 reads and displays text from a file, and Problem 4 processes and visualizes elevation data from a specific text file. Each problem includes MATLAB code snippets for data manipulation and visualization.

Uploaded by

Zane Williams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views5 pages

Homework 5 B

The document contains a homework assignment by Zane Williams, dated November 19, 2020, which includes three problems related to data analysis using MATLAB. Problem 2 involves plotting air and water temperatures from Atlantic City data, Problem 3 reads and displays text from a file, and Problem 4 processes and visualizes elevation data from a specific text file. Each problem includes MATLAB code snippets for data manipulation and visualization.

Uploaded by

Zane Williams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Table of Contents

........................................................................................................................................ 1
Problem 2 - Atlantic City Temperature Data ............................................................................ 1
Problem 3 - Surprise! .......................................................................................................... 2
Problem 4 - 'BM_dem_ascii.txt' graph .................................................................................... 4

% Homework #5b
% Zane Williams
% 19 November 2020

Problem 2 - Atlantic City Temperature Data


clear; clc;

data = dlmread('AtlanticCity_TemperatureData.csv'); % load data


dates = data(:,1);
fdates = dates(1:end) - dates(1); % subtracts the first date value
from all other dates
col_fdates = transpose(fdates); % tells you the fractional number of
days since Jan 1, 2015 at midnight

figure;
hold on
plot(col_fdates, data(:,2),'r')
plot(col_fdates, data(:,3),'b') % plots air and water temperature vs
day

% pretty up the graph


grid on
title('Atlantic City Air and Water Temperatures in
2015','FontWeight','bold','FontSize',16);
xlim([0 365])
legend('Air Temp. (C)', 'Water Temp. (C)')
xlabel('Date (Months of 2015)','fontsize',14)
ylabel('Temperature (Degrees Celcius)','fontsize',14)
xticks([1,32, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]) %
creates ticks at each month
xticklabels({'January','February','March','April','May','June','July','August','Sep
set(gcf, 'position', [260 378 1225 625]);

1
Problem 3 - Surprise!
clear;clc;
ct = 0; % a counter
fid = fopen('surprise.txt', 'r'); % open file for reading
while feof(fid) ~= 1
ct = ct + 1; % increase counter by 1
dataset{ct} = fgetl(fid); % grab entire line of text from file, store
as string in the ct^th cell
end

for i = 1:ct
for j = 1:length(dataset{i})
fprintf('%s', dataset{i}(j)); % writes data to text file
pause(0.001);
end
end

_______
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I

2
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;'
`8888888I8888888888888b, II888888888'
888888I8888888888888888b ,II888888888
,888888I88888888888888888 ,d88888888888
d888888I8888888888ZZZZZZZ ,ad888888888888I
8888888I8888ZZZZZZZZZZZZZ
,d888888888888888'
888888IZZZZZZZZZZZZZZZZZZ ,d888888888888P'8P'
Y888ZZZZZZZZZZZZZZZZZZZZZ ,8888888888888, "
,ZZZZZZZZZZZZZZZZZZZZZZZZd888888888888888,
,ZZZZZZZZZZZZZZZZZZZZZZZZZZZ888888888888888888a,
_
,ZZZZZZZZZZZZZZZZZZZZ888888888888888888888888888888ba,_d'

,ZZZZZZZZZZZZZZZZZ888888888888888888888888888888888888888888bbbaaa,,,______,ZZZZZ

3
Problem 4 - 'BM_dem_ascii.txt' graph
clear;clc;

% a) load first 5 lines of the file


fid2 = fopen('BM_dem_ascii.txt', 'r');
textlines = cell(5,1);
for ii = 1:5
textlines(ii) = {fgetl(fid2)};
end

% convert to numeric data


ncols = str2double(textlines{1} (15:end));
nrows = str2double(textlines{2} (15:end));
xllcorner = str2double(textlines{3} (15:end));
yllcorner = str2double(textlines{4} (15:end));
cellsize = str2double(textlines{5} (15:end));

x = [xllcorner:cellsize:(((ncols)*cellsize)+xllcorner)];
y = [yllcorner:cellsize:(((nrows - 6)*cellsize)+yllcorner)];

BM = cell2mat(textscan(fid2,'','delimiter',' ','headerlines',6)); %
loads elevation data and turns into a regular matrix

s(1) = subplot(1,2,1);
pcolor(x - x(1), y - y(1), BM); shading flat;
colorbar; caxis([-3 2.5])
xlabel('x (m)'); ylabel('y (m)'); title('\bf Original Data')
set(s(1),'layer','top')

neg_vals = find(BM < 0); % find negative values


BM(neg_vals) = NaN; % turns negative values to Nan
BM_mod = BM;

limits = [get(s(1), 'xlim') get(s(1), 'ylim')];


s(2) = subplot(1,2,2);
pcolor(x - x(1), y - y(1), BM_mod);
shading flat
colorbar;
caxis([-3 2.5]);
axis(limits);
xlabel('x (m)');
ylabel('y (m)');
title('\bf Elevations > 0 Only');
set(s(2),'layer','top');

4
Published with MATLAB® R2020a

You might also like