Q:

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

0

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. Create a data file that stores on each line the year, an alphanumeric code representing the location, and the measured well depth that year. Write a script that will read the data from the file and determine whether or not the average well depth has been lowered. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now