Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

used mathlab Function Name: weatherStats Inputs: 1. 2. (double) A 1xM vector of

ID: 3879290 • Letter: U

Question

used mathlab

Function Name: weatherStats Inputs: 1. 2. (double) A 1xM vector of temporature values throughout the day (char) A character vector describing the day's weather Outputs: 1. (char) A formatted character vector describing the day's weather statistics Function Description For your new job at NOAA, you need to process weather data. You are given a vector of temperatures recorded during the day, which you must analyze to determine the maximum and average tomperature for the day. You also have a written description of the day's weather from NOAA, which is written in all caps. This description needs to be turned to lowercase so it is easier to read. Finally, combine all of this information into a formatted character vector The outputted vector should be in the following format 'Today's weather was «description», with a high temperature of max temperature degrees and an average temperature of degrees Example [out] - weatherStats ([23, 26, 28, 35, 3, FROSTY) out 'Today's weather was frosty, with a high temperature of 35 degrees and an average temperature of 28 degrees. Notes: The vector of temperatures can be any length. Average and max temperatures should be rounded to the nearest whole number. The weather description may contain spaces. . . You can use two single apostrophes to get a single apostrophe in a character vector . o var Today's weather var-> Today's weather Hints: . The function sprintf) will be useful.

Explanation / Answer


Given below is the matlab code for the question. It uses built-in max() and mean() functions. Let me know in case you wanted to do it using for loop and not built-in functions.
Please do rate the answer if it was helpful. Thank you

Save the code in weatherStats.m
===============================

function out = weatherStats(temp, desc)

mx = max(temp); %find max temp
avg = round(mean(temp)); % find average temp
desc = lower(desc); %convert description to lowercase

out = sprintf("Today's weather was %s, with high temperature of %d degrees and an average temperature of %d degrees.", desc, mx, avg);
end


==========================


At command prompt, you can type
> [out] = weatherStats([23, 26, 28, 35, 30], 'FROSTY')

output
out = Today's weather was frosty, with high temperature of 35 degrees and an average temperature of 28 degrees.