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

asmay and a scalar A. stracturearay that will be passed to this function will ha

ID: 2293115 • Letter: A

Question






asmay and a scalar A. stracturearay that will be passed to this function will have a field speed anda where both of those distance [m) in distance number of se fields will contain these data. (2, 4) im speed in [m/s] and (6, 8 in . Also, the scalar input to your function will always equal the each component stracture, a time that equals the distance divided by the speed. Your function should then caleulate the average such time, averaging over all component structures. Your function will returs this average time Prepare a code section within your script that tests this function. Your test structure array must have at least two component structures(100pts)

Explanation / Answer

a) function:

function tavg=avgtime(Data,n)
%
v=Data.Speed; % taking the speed values into an array V
d=Data.Distance; % taking the distance values into an array D
t=rdivide(d,v); % dividing distance with speed will give time
tavg=mean(t); % averaging all the times

b) testing

%%
Data.Speed=[2 4];
Data.Distance=[6 8];
tavg=avgtime(Data,2)