Environmental engineers are trying to determine whether the underground aquifers in a region are being drained by a new spring water company in the area. Well depth data has been collected every year at several locations in the area
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:9| Question number:30.9
All Answers
total answers (1)
Ch9Ex30.m
% Read in well depth data for the last few years to
% determine whether the average depth has lowered or not
fid = fopen('wells.dat');
if fid == -1
disp('File open not successful')
else
aline = fgetl(fid);
aveyear1 = avedepth(aline);
while ~feof(fid)
aline = fgetl(fid);
aveyearx = avedepth(aline);
end
if aveyearx < aveyear1
disp('The average well depth was lowered')
else
disp('The average well depth was not lowered')
end
%Error-check file close
closeresult = fclose(fid);
if closeresult == 0
disp('File close successful')
else
disp('File close not successful')
end
end
avedepth.m
function outave = avedepth(aline)
% Calculates the average well depth for a year
% Format of call: avedepth(a line from file)
% Returns the average well depth
[year, rest] = strtok(aline);
[code, rest] = strtok(rest);
[depth1, rest] = strtok(rest);
[code, rest] = strtok(rest);
[depth2, rest] = strtok(rest);
[code, depth3] = strtok(rest);
outave = mean([str2num(depth1) str2num(depth2) str2num(depth3)]);
end
need an explanation for this answer? contact us directly to get an explanation for this answer