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

OverLoaded Matlab Functions!!! BELOW IS the the assignment and the required data

ID: 3764648 • Letter: O

Question

OverLoaded Matlab Functions!!!

BELOW IS the the assignment and the required data file that needs to be used in the function!!!

NOTE: I can't seem to upload the data file (.dat) but it is not needed all that is needed is the function Thank You

Learning Objectives Use varargin in parameter list to overload a function . . Use reshape () function to reshape a subset of an array Use min (), max (), and mean () functions Use operators on entire matrices to avoid loops . . Instructions In this assignment, you will create an overloaded Matlab function with the name tempavg. This function will be overloaded, meaning it can be called with different parameter lists. In Matlab, this can be accomplished using varargin, a special parameter that captures zero or more optional parameters in a parameter list. The function you will write determines the average difference between the daily high and low temperature. There are two possible inputs: (1) a pair of Julian days as numerical values, or (2) the month as a three-letter abbreviation (all caps). To overload, the function with have a parameter varargin listed last. The function will be function [ avg ] = temp avg (data, varargin) Inside the function, the variable varargin is a cell array, a data type that holds an array of different separate data type. For example, it can hold 2 numerical values, a string, and a function handle. In this implementation, it will have either (1) 2 numeric values, or (2) a single string. Use an if-else construct and nargin to access the correct cell array values. Individual cells are accessed with ) brackets. For example, the first element is varagin 1). Load the temperature data outside the function bv downloading the date file provided and using load temperature 2 0 1 4.dat; do NOT use any loops. Do the following Get a subset of the data using colon index operators Reshape the matrix into a 24 x n matrix, where n is the number of days Use max () andmin () on the reshaped matrix to get row vectors of the values Use mean () on the resulting row vectors to get a single return value: avg . . Your pro gram must have or do the following: Do NOT use any loops Use reshape, max (), min (), andmean () Use varargin. Sample Output >>tempavg (tempe rature 2014,1,3) ans - 19.3333 tempavg (tempe rature2014, 'FEB' ans 22.9786 tempavg (tempe rature 2014,100,300) ans - 18.2224 Julian day is I for Jan 1, 32 for Feb. I, and 365 for December 31

Explanation / Answer

function [avg] = tempavg(data,varargin)
   if (varargin == 2)
       avg = 0.0;

       % please find min,max and mean here becuase i do not know how the file data is arranged
       % varargin will 2 agrument in this if case
       avg = avg + data(varargin[0]:varargin[1],1)
       avg = avg / ((varargin(:,2)-varargin(:,1)));
   else
       if (varargin == 'JAN')
           avg = tempavg(data,1,31)
       elseif (varargin == 'FEB')
           avg = tempavg(data,32,59)
       elseif (varargin == 'MAR')
           avg = tempavg(data,60,90)
       elseif (varargin == 'APR')
           avg = tempavg(data,91,120)
       elseif (varargin == 'MAY')
           avg = tempavg(data,121,151)
       elseif (varargin == 'JUN')
           avg = tempavg(data,152,181)
       elseif (varargin == 'JUL')
           avg = tempavg(data,182,212)
       elseif (varargin == 'AUG')
           avg = tempavg(data,213,243)
       elseif (varargin == 'SEP')
           avg = tempavg(data,244,273)
       elseif (varargin == 'OCT')
           avg = tempavg(data,274,304)
       elseif (varargin == 'NOV')
           avg = tempavg(data,305,334)
       elseif (varargin == 'DEV')
           avg = tempavg(data,335,365)
       end
   end
end