Question
matlab help

History Bookmarks People Window Help × assign07-1.pdf chappelle/Downloads/assign07-1.pdf Submit assign07. printkaterLevels..p
History Bookmarks People Window Help xassign07-1.pdf tinchappelle/Downloads/assign07-1.pdf O D Insert these comments at the t
.pdf o Indent blocks as needed. Use Smart Indent. o Divide your solution program code into sections as noted in the algorithm
*****CONSTANT*****
NUM_MONTHS = 12;
FIRST_YEAR = 2013;
LAST_YEAR = 2016;
%*****INPUT*****
months = 1:NUM_MONTHS;
years = FIRST_YEAR:LAST_YEAR;
% read data file
lake_powell = load( 'lake_powell.txt' );
% OR load lake_powell.txt
% print with title and year column headings.
fprintf(' Lake Powell Water Levels (in feet)\n')
fprintf('%8d ', years)
fprintf('\n')
% print contents of lake_powell
for month = 1:NUM_MONTHS
fprintf('%9.2f', lake_powell(month,:))
fprintf('\n')
end
% PART B ==========================================================
fprintf('\nPART B: Determine average elevation of water level for each year and overall average\n')
yearAve = mean(lake_powell);
fprintf(' Average for Each Year (in feet)\n')
fprintf('%8d ', years)
fprintf('\n')
fprintf('%9.2f', yearAve)
fprintf('\n')
overallAve = mean(yearAve);
fprintf(' Overall average: %.2f feet\n', overallAve)
% PART C ==========================================================
fprintf('\nPART C: Determine how many months of each year > overall average\n')
for year=1:length(years)
over_average(year)=length(find(lake_powell(:,year)>overallAve));
end
fprintf(' During %5.0f the lake was above average for %3.0f months \n',...
[years;over_average])
% PART D ==========================================================
fprintf('\nPART D: Determine and print average elevation of the water for each month\n')
monthly_average=mean(lake_powell');
table = [months;monthly_average];
fprintf(' Average elevation (in feet) of the water for each month\n')
fprintf(' Month Elevation\n')
fprintf(' %2d %9.2f\n',table)
History Bookmarks People Window Help × assign07-1.pdf chappelle/Downloads/assign07-1.pdf Submit assign07. printkaterLevels..prin tkaterievelsummary.n via Refore you start wrining your program Save a copy of lake powel1.txt in the folder where f gno7. Program: Modify your assign06a.m AssignoS and assigno6a requirements m to include the following user-defined function definitions and output still apply except plot in part E is omitted New commands Function names should be as given. Variable names may be different, but the order and quantity should be as given. NO global variables print water levels with title and year column headi tunetion 1 -printHaterteveist lake powell, years, NUM MONTHS) % print water level sumary stats function printwaterlevel Summary! lake powell, nonths, years tle and year column The following sare subgetions used by printHaterteve1Summary and are losated in printatertevelSummary % PART B Determine and print average levation of water level for each year and overall average function overal İAve-printYearAve( ake poveli, years ) PARTc % Determine and print how many months of each year > overall average function [] PrintAboveAve ( lake_povel1, years, overal İAv. ) % PART D Determine and print average elevation of the vater for each month funetion 1 -printMonthAve( lake _powel1, months ) Your assign07.m should ONLY Check that the DATA file is available as in assign06a.m Assign values to constants See the Structare Diagram below for the ßlow between functions INPUT Read the file as in assign06a.m Create vectors needed to send to the functions OUTPUT Use the following functions for output printkaterLevels and printHaterievelSummary The rest of the work will be done in the functions
History Bookmarks People Window Help xassign07-1.pdf tinchappelle/Downloads/assign07-1.pdf O D Insert these comments at the top and throughout each fil for all ฉssignments scripts: See Standards for Documentation of MATLAB Programs on the Canvas Resources page Include the follow comments at the beginning of this( o submitter's name, GROUP # and ALL) files. Grade of ZERO for files if submitter name not part of Canvas group Not is a group other group members' names GROUPH is "BeR.For your owa protection, type "nons" if submitting alone. t program file name, ex. assiga)2a m s due date of the assignment % statement about collaboration REQUIRED, even if you didm't collaborate.See sy llabus f for examples a short narrative about what the file des MODIFY narrative to include e mments threughout your program Use the algorithm given as co o Observe the instractor's nule for naming variables o Use ALL CAPS for constants variable name o Start other variables with lower case D o Use descriptive variable names. Use Sample Input/Output as a guide. a5 POINTS PENALTY for set jaining a group on Caavas Groups can be 2-4 students DO NOT jela a group unless yea have D Code clarity: o Indent blocks as needed. Use Smart Indent. o Divide your solution program code into sections as noted in the worked with the other algorithm. Use blank lines as needed to group statements. Use section comments as well as the algoritha step comments Remove statements from previous assignments that do not apply to the current requirements de, you will be remeved from the greap and given the grade of ere o o MINUS FIVE POINTS for not having the CORRECT CURRENT GROUP NUMBER in your Use comments to show units. Use the CONSTANT and variable names; not numbers Exceptions are incrementers and numbers without identity No extra output, ie. use semicolons MATLAB script file MATLAB script file Submit via Canvas assigno7.m printwaterlevels.m printWaterLevelSummary.n MATLAB script file Structure Diagram Assign07 lake_powell,years
.pdf o Indent blocks as needed. Use Smart Indent. o Divide your solution program code into sections as noted in the algorithm. Groups can be 2-4 stud Use blank lines as needed to group statements. o Use section comments as well as the algorithm step comments. o Remove statements from previous assignments that do not apply to the DO NOT join a group unless worked with the other member do, you wil be remeved from th and given the grade of zere current requirements. MINUS FIVE POINTS for n having the CORRECT CURRE Use comments to show units. □ Use the CONSTANT and variable names, not numbers. GROUP NUMBER in your Exceptions are incrementers and numbers without identity No extra output, i.e. use semicolons Submit via Canvas: assign07.m printwaterLevels.m printWaterLevelSummary MATLAB script file MATLAB script file MATLAB script file .m Structure Diagram Assign07 lake_powell, months, years lake_powell,years, NUM MONTH printWaterLevel() lake_powell, printWaterlevelSummary lake_powell, ke powell, years, overallAve mont years overallAve printAboveAve) printAboveAve() printYearAve() 2
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find below required MATLAB code along with necessary details in comments:

--------------------------------------------- assign07.m

clear all; clc;

NUM_MONTHS = 12;
FIRST_YEAR = 2013;
LAST_YEAR = 2016;
WATER_LEVELS = 'lake_powell.txt';
%*****INPUT*****
% open file
[ fileID, msg ] = fopen( WATER_LEVELS, 'r' );
% file available ?
if fileID < 0
fprintf( '%s \n', msg )
else
% file available continue
years = FIRST_YEAR:LAST_YEAR;
% read lake_powell.txt
for month = 1:NUM_MONTHS
for year = 1:length(years)
lake_powell(month,year) = fscanf(fileID, '%f', 1);
end
end
% **** OUTPUT ****
% determine average elevation of water level for each year and overall average\n')
printWaterLevel(lake_powell, years, NUM_MONTHS);
end % good file open

NUM_MONTHS = 12;
FIRST_YEAR = 2013;
LAST_YEAR = 2016;
WATER_LEVELS = 'lake_powell.txt';
months=1:1:NUM_MONTHS;
%*****INPUT*****
% file avaialable ?
if ~exist( WATER_LEVELS, 'file' )
fprintf( 'File not found\n' )
else
% read data file
[ lake_powell(:,1),lake_powell(:,2) ] = textread( WATER_LEVELS, '%f%*f%*f%f' );
% **** OUTPUT ****
printWaterLevelSummary(lake_powell, months, NUM_MONTHS);
end % file found

----------------------------------------------------------------- printMonthAve.m

function []=printMonthAve(lake_powell,months)
monthly_average=mean(lake_powell');
table = [months;monthly_average];

fprintf('\n Average elevation (in feet) of the water for each month\n')
fprintf(' Month Elevation\n')
fprintf(' %2d %9.2f\n',table)
end

---------------------------------------------------------- printWaterLevel.m

function []=printWaterLevel(lake_powell, years, NUM_MONTHS)

% determine average elevation of water level for each year and overall average\n')
yearAve = printYearAve(lake_powell, years);
fprintf(' Average for Each Year (in feet)\n')
fprintf('%8d ', years)
fprintf('\n')
fprintf('%9.2f', yearAve)
fprintf('\n')
overallAve = mean(yearAve);
fprintf(' Overall average: %.2f feet\n', overallAve);

fprintf('Months for which water level is above average:\n');
printAboveAve(lake_powell, years,yearAve);
end

----------------------------------------------------------- printWaterLevelSummary.m

function []=printWaterLevelSummary(lake_powell, months, NUM_MONTHS)

% Determine and print average elevation of the water for each month\n')
printMonthAve(lake_powell,months)

end

------------------------------------------------------------- printAboveAve.m

function []=printAboveAve(lake_powell, years,overallAve)
for k=1:length(years)
aboveAve = find(lake_powell(k,:)>overallAve(k));
countAve(k)=length(aboveAve);
end

fprintf('%8d ', years)
fprintf('\n')
fprintf('%8d ', countAve)
fprintf('\n')

SAMPLE OUTPUT

Command Window Average for Each Year (in feet) 2016 2013 3678.11 3665.32 3637.93 3607.92 2014 2015 Overall average: Months fo

Add a comment
Know the answer?
Add Answer to:
Matlab help *****CONSTANT***** NUM_MONTHS = 12; FIRST_YEAR = 2013; LAST_YEAR = 2016; %*****...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • BME 2013 Spring 2019 Exam 3 Matlab Review Sheet 1. Given the vector of patient body temperatures ...

    can anyone help me figure out how fo write matlab code for these problems? BME 2013 Spring 2019 Exam 3 Matlab Review Sheet 1. Given the vector of patient body temperatures T (98.6, 102, 101, 99,98.9, 102.1, 100.3, 101.2, 98.4 97.6, 100] use conditional statements and loops to write a program that determines and displays (using the fprintf function) the number of patients with a fever and patients without a fever. The program must ask the user to input the...

  • USE MATLAB TO WRITE A CODE FOR THIS 2. Writ example 4.5% as 4.5) and the...

    USE MATLAB TO WRITE A CODE FOR THIS 2. Writ example 4.5% as 4.5) and the number of monthly payments (use the Calculate the down payment using the percent down payment e e a program that gets a cost, percent down payment, annual interest rate as a percent (for ntered, the loan amount (cost - own payment) and monthly interest rate as a decimal number -not a percent. Call your payment function to calculate the payment on the loan amount....

  • MATLAB : Practice-4 (Oct. 31/ Nov. 1) Seat No. Name: Solve the following problems and write...

    MATLAB : Practice-4 (Oct. 31/ Nov. 1) Seat No. Name: Solve the following problems and write in the answers in blue and the plot in the box. Save the file in a pdf format and submit the answer script file and the pdf file to E-Class. 1. Re-do the Sample Problem 6-11 (Flight of a model rocket), but with the following conditions. - 16N force during the first 0.2 second - Parachute open when the downward velocity reaches 25 m/s...

  • Create a single script (.m file) to complete this assignment. Unless directed otherwise, use meaningful variable...

    Create a single script (.m file) to complete this assignment. Unless directed otherwise, use meaningful variable names for each variable: do not use the default variable ans to store your results. For this assignment do not suppress your output with semi- colons (). Each problem (ie. Problem 1. Problem 2, and Problem 4) should be in a separate cell, using the cell mode feature of MATLAB; the subparts should all be contained in the same cell as the parent problem....

  • Use the program MATLAB to answer the following question:Use the program MATLAB to answer the following...

    Use the program MATLAB to answer the following question:Use the program MATLAB to answer the following question: KE Mona File Use The Program MATLA x 0 Info Assignment 8, Matlab, spring 2017.docx O Download Close box 2/2 5. Write a program that accepts a year and determines whether the year is a leap year. Use the mod function. The output should be the variable extra day, which should be 1 if the year is a leap year and 0 otherwise....

  • MATLAB question: I have written a code to solve for a metals resitance. Here is the...

    MATLAB question: I have written a code to solve for a metals resitance. Here is the problem statement: Part 1 (Algorithms) – due Friday: Think about how you might solve the problem of calculating the resistance of a given group of metals depending on the type of metal, the length of the wire and the area of the wire (if given the diameter only – so you must calculate the area). Write instructions (an algorithm) for a script that behaves...

  • The first two parts should be solved by Matlab. This is from an intro to Numerical...

    The first two parts should be solved by Matlab. This is from an intro to Numerical Analysis Class and I have provided the Alog 3.2 in below. Please write the whole codes for me. Alog3.2 % NEWTONS INTERPOLATORY DIVIDED-DIFFERENCE FORMULA ALGORITHM 3.2 % To obtain the divided-difference coefficients of the % interpolatory polynomial P on the (n+1) distinct numbers x(0), % x(1), ..., x(n) for the function f: % INPUT: numbers x(0), x(1), ..., x(n); values f(x(0)), f(x(1)), % ...,...

  • (a) (4 points) Fill in the blanks in the following MATLAB function M file trap so...

    (a) (4 points) Fill in the blanks in the following MATLAB function M file trap so that it implements the composilu trapezidul rulo, using a soquence of w -1,2, 4, 8, 16,... trapezoids, to approximatel d . This M file uses the MATLAB built-in function trapz. If 401) and y=() f(!)..... fr. 1)). 3= ($1, then the execution of z = trapz(x, y) approximates using the composite trapezoidal rule (with trapezoids). (Note that the entries of are labeled starting at...

  • Urgent: Help with MatLab Program Create a Matlab function called seasonif. m which assigns to the...

    Urgent: Help with MatLab Program Create a Matlab function called seasonif. m which assigns to the numerical value of a month within the year a numerical value for the particular season in which that month occurs (see Table 2 above for numerical values to assign seasons). As usual, January is mouth 1, February is mouth 2, mid so on. Your function should allow decimal values (e.g. 4.68 should be considered part of April), but any value less than 1 or...

  • i need help in this assignment by using matlab. codes only or capture the solutionPlot t...

    i need help in this assignment by using matlab. codes only or capture the solutionPlot t versus v with line width 1.5, dotted, red colored line, triangle shaped, marker with size 10, black edge, and green face. A1-2. a. Determine the drae coefficient (cd) using the equation: cd = g*m/upsilon^2from the exploratory data analysis below: g=9.81 b. Find out average, maximum, and minimum of cd by the command meant(cd), max(cd), and min(cd) respectively. c. Determine the predicted terminal velocity by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT