Question: Define a local function MaxMinEnergy according to the criteria below. The function should take in one input, EnergyByMonth, and return four outputs MaxEnergy, MaxMonth, MinEnergy,
Define a local function MaxMinEnergy according to the criteria below. The function should take in one input, EnergyByMonth, and return four outputs MaxEnergy, MaxMonth, MinEnergy, and MinMonth. Remember, local functions are defined at the bottom of your script.
a Calculate a variable MaxEnergy as the maximum value for a given input EnergyByMonth.
b Calculate a variable MinEnergy as the minimum value for a given input EnergyByMonth.
c Now that you have determined MaxEnergy, calculate a logical vector tempMaxIdx where all values are false except for a single true value where MaxEnergy occurs in the EnergyByMonth vector. For example, if MaxEnergy occurs at the th position in the EnergyByMonth vector, then the resulting logica vector would be HINT: use a relational operator to calculate tempMaxIdx where EnergyByMonth is equal to MaxEnergy.
d Repeat the step above to calculate tempMinldx where all values are false except for a single true value where MinEnergy occurs in the EnergyByMonth vector.
e Create a variable Month that is a vector that starts at and steps by up to
f Calculate a variable MaxMonth by indexing the Month variable with the tempMaxIdx variable.
g Repeat the step above to calculate a variable MinMonth by indexing the Month variable with the tempMinIdx variable.
h All calculations should be suppressed.
i Use the fprintf function to create the text below when the MaxMinEnergy function is called, ie the fprintf statement should be inside your function definition. Note, the highlighted text is dynamic so it should change as the variables change. Note the different formats and decimal places of the dynamic texts. Note, there are no "new lines"
in the text below; it is one continuous line.
The maximum energy used was in month and the minimum energy used was in month
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
