Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A.) Revise your assign05.m by adding the exist() function to print a message only if the data file is not available. The output should be

A.) Revise your assign05.m by adding the exist() function to print a message only if the data file is not available. The output should be the same as with assign05.m.

B.) REMOVE UNNECESSARY STATEMENTS FROM PREVIOUS PROGRAMS. INCLUDE APPROPRIATE COMMENTS. Check the file ID to determine if the file is available.

Only print message if file is not available. Use nested for loops to read one water level value at a time into the lake_powellmatrix. lake_powell(month,year) = fscanf(fileID, '%f', 1);. Use mean to determine the average elevation of the water level for each year and the

overall average for the four-year period over which the data were collected. Print the

yearly average vector and the overall average with labels as shown below.

Additional Problem Constants: (with unit comments)data file name

New commands

fopen() fscanf()nested for loops

Continue to use

fprintf()

Print water level with 2 decimal places Print year, month with 0 decimal places Align numbers under headings Use constant names

New commands

textread()

save selected columns of a file

Continue to use

fprintf()

Print water level with 2 decimal places Print year, month with 0 decimal places Align numbers under headings

Use constant names

Output: Average for Each Year (in feet) 2013 2014 2015 2016

3579.90 3585.70 3600.78 3602.36 Overall average: 3592.18 feet 

C.) REMOVE UNNECESSARY STATEMENTS FROM PREVIOUS PROGRAMS. INCLUDE APPROPRIATE COMMENTS. Use exist() to determine if the file is available. Only print message if file is not

available. Use textread() to save the first and last years into a two column matrix.

Do not save the other years. Do not use a loop. Print the lake_powell matrix with title and year column headings.

Do not use a loop to print matrix. Use mean to determine and print the average elevation of the water for each month for

the four-year period. Create a 2-column table of the results; print the table. See

example 7.2, p.254.

Problem Constants: (with unit comments)as given in previously 05 and 06

Output:

 Lake Powell Water Levels (in feet) 2013 2016 
 3594.38 3601.41 3589.11 3598.63 3584.49 3597.85 3583.02 3599.75 3584.70 3604.68 3587.01 3610.94 3583.07 3609.47 3575.85 3605.56 3571.07 3602.27 3570.70 3601.27 3569.69 3599.71 3565.73 3596.79 

Average elevation (in feet) of the water for each month Month Elevation

 1 3597.89 2 3593.87 3 3591.17 4 3591.39 5 3594.69 6 3598.98 7 3596.27 8 3590.70 9 3586.67 
 10 3585.98 11 3584.70 12 3581.26

previous:

image text in transcribedimage text in transcribedimage text in transcribed

textfile above

CONST AN load ( 'lake_powell.txt'); INPUT % read data file years 2013:1:2016 ); fprintf(nLake Powell Water Levels (in feet) '); % print title and year column headings. for i-1: length(years) fprintf('%6.0d\t', years (i)); end % print contents of lake-powell for i-1:size(lake_powell,1) fprintf('n) for j-1:size(lake_powell,2) fprintf(*%.2f\t", lake-powell( i, j )) ; end end fprintf(n) % PART B: use mean to determine average elevation fprintf(n) fprintf(n PART B: Determine average elevation of water level for each year and overall average); mean-each-year = mean(lake-powell, 1); fprintf('n Average for Each Year (in feet) ) for i-1: length(years) fprintf('%9.0d", years (1) ) ; end fprintf(n) for i-1: length(mean_each_year) fprintf('%10.2f, mean_each year(i)); end overall-mean= fprintf(. mean(mean-each-year); Overall average : %10.2f feet. , overall-mean); %PART C: use find and length to determine how many months exceed average fprintf(n) fprintf(n PART C: Determine how many months of each year > overall average) number-of-months = zeros(1, size (lake-powell, 2 )); lfor i-1:size(lake_powell, 2) number_of_months(i)length (find (lake_powell(:,i)>overall_mean)); end lfor i-1:length (years) fprintf(' end During %d the lake was above average for %d months.,years(i),number-of-months(1)); fprintf(n) %PART D: print average elevation of water fprintf(n PART D: Determine and print average elevation of the water for each month'); mean_each_monthmean (lake_powell,2) fprintf(Average elevation (in feet) of water for each month Month Elevation; lfor i-1: length (mean_each_month) fprintf(' %6.0d\t%1 1.2f. ,, mean-each, month (1) ) ; end fprintf(n) %PART E: plot water level values date 2013:1/12:2017-1/12; plot(date, lake_powell(:)); title( 'Water Level Values in Lake Powell'); xlabel( 'Year) ylabel('W ater level, ft' 3.5943800e+003 3.5891100e+003 3.5844900e+003 3.5830200e+003 3.5847000+003 3.5870|00+003 3.5830700e+003 3"5758500+003 3.5710700e+003 3.5707000e+003 3.5696900+003 3.5657300e+003 3.5634100e+003 3.5603500e+003 3.5574200e+003 3.5575200e+003 3.57|6000+003 3.5980600+003 3.6077300e+003 3.6049600+003 3.6022000e+003 3.6023100e+003 3.6026500+003 3.6001400e+003 3.5962600e+003 3.5919400e+003 3.5892200e+003 3.5899400e+003 3.5982700+003 3.6093600+003 3.6087900e+003 3.6049300+003 3.6020800e+003 3.6061200e+003 3.6074600+003 3.6049600e+003 3.6014100e+003 3.5986300e+003 3.5978500e+003 3.5997500e+003 3.6046800+003 3.6109400+003 3.6094700e+003 3.6055600+003 3.6022700e+003 3.6012700e+003 3.5997|00+003 3.5967900e+003

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions