Question

Function Name: sportsStats Inputs: 1. (double) An Nx5 array representing the stats of different football teams 2. (double) ThNotes: If there are an odd number of teams remaining before step 5, the middle team should remain in the array There will not

MATLAB code help!!!

Function Name: sportsStats Inputs: 1. (double) An Nx5 array representing the stats of different football teams 2. (double) The cutoff for total penalties Outputs: 1. (double) An Mx5 array representing the updated stats Background: You just finished watching the Patriots defeat the Rams in Super Bowl LIII, and you just can't wait for the next season to start. However, instead of waiting around for the next football season, you decide to take matters into your own hands and create a MATLAB function that will determine which teams will be among the top competitors for the Super Bowl LIV ring Function Description You will be given an Nx5 array of stats, with each row representing an NFL team. Each of the columns will represent, from left to right, the following: 1) Average points per game, 2) Average rushing yards per game, 3) Average passing yards per game, 4) Total number of first downs, and 5) Total number of penalties. In order to thoroughly analyze these teams, you must make the following changes to the stats array: 1. Append a new column to the right of the array that contains the average total yards per game, calculated by adding together the average rushing yards and average passing yards 2. Remove all teams with a total number of penalties higher than the given cutoff. 3. Remove the column representing the total number of first downs. 4. Sort the rows in descending order by the average number of points per game. 5. Remove the bottom half of the teams from the array, so you are left with the teams with the best points per game. Example: PPG ARY APY FD P [26.8 90.3 313.0 378 111 >stats 25.1 126.3 236.3 333 105 20.3 103.8 223.5 325 94 26.3 121.1 222.8 331 97 105 >>cutoff >> newStats sportsStats (stats, cutoff) PPG ARY APY P ATY 26.3 121.1 222.8 97 343.9 >>newStats => 25.1 126.3 236.3 105 362.6 1
Notes: If there are an odd number of teams remaining before step 5, the middle team should remain in the array There will not be any ties for average points per game between teams.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM:

function stats = sportsStats(stats, cutoff)

% appending new column after last column

% stats(:, 2) + stats(:, 3) will give average total yards per game

stats(:, end+1) = stats(:, 2) + stats(:, 3);

% removing all teams with total penalties greater than given cutoff

% stats(stats(:, 5) > cutoff, :) = [] this will delete the rows where

% penalties are greater than cutoff

stats(stats(:, 5) > cutoff, :) = [];

% deleting column 4 from the matrix

stats(:, 4) = [];

% sortrows() will sort the rows based on column 1 in descending order

stats = sortrows(stats, 1,"descend");

% finding the number of rows, ~ is used when we don't require that output

[size_row , ~] = size(stats);

% finding the half of number of rows rounded to positive infinity

size_row = ceil(size_row / 2);

% finding the upper half of the matrix

stats = stats(1:size_row, :);

end

COMMAND WINDOW:

stats1

stats1 =
26.8000 90.3000 313.0000 378.0000 111.0000
25.1000 126.3000 236.3000 333.0000 105.0000
20.3000 103.8000 223.5000 325.0000 94.0000
26.3000 121.1000 222.8000 331.0000 97.0000

stats2

stats2 =
26.8000 90.3000 313.0000 378.0000 111.0000
25.1000 126.3000 236.3000 333.0000 105.0000
20.3000 103.8000 223.5000 325.0000 94.0000
26.3000 121.1000 222.8000 331.0000 97.0000
26.8000 126.3000 223.5000 331.0000 93.0000
25.1000 103.8000 222.8000 378.0000 90.0000

cutoff

cutoff =
105

newStats1 = sportsStats(stats1, cutoff)

newStats1 =
26.3000 121.1000 222.8000 97.0000 343.9000
25.1000 126.3000 236.3000 105.0000 362.6000

newStats2 = sportsStats(stats2, cutoff)

newStats2 =
26.8000 126.3000 223.5000 93.0000 349.8000
26.3000 121.1000 222.8000 97.0000 343.9000
25.1000 126.3000 236.3000 105.0000 362.6000


SCREENSHOTS:

MATLAB Online R2019a + https://matlab.mathworks.com 10 Minutes to pand Turn websites into. G knn algorithm-Go... IApps GettinMATLAB Online R2019a + C https://matlab.mathworks.com THE SCRAPINGHUB.. Getting Started Imported From Fire... Turn websites iMATLAB Online R2019a + C https://matlab.mathworks.com THE SCRAPINGHUB.. Getting Started Imported From Fire... Turn websites i

Hope this helps!

Add a comment
Know the answer?
Add Answer to:
MATLAB code help!!! Function Name: sportsStats Inputs: 1. (double) An Nx5 array representing the stats of different foo...
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
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