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 Gettin](//img.homeworklib.com/images/c0e2a8a8-de74-4df0-8f0d-0daef1a5e68d.png?x-oss-process=image/resize,w_560)
![MATLAB Online R2019a + C https://matlab.mathworks.com THE SCRAPINGHUB.. Getting Started Imported From Fire... Turn websites i](//img.homeworklib.com/images/3f1867e7-1e36-4307-93f0-337fc59cc03f.png?x-oss-process=image/resize,w_560)
![MATLAB Online R2019a + C https://matlab.mathworks.com THE SCRAPINGHUB.. Getting Started Imported From Fire... Turn websites i](//img.homeworklib.com/images/9088a1dd-89cb-440c-9711-633bd5b0f456.png?x-oss-process=image/resize,w_560)
Hope this helps!
MATLAB Online R2019a + https://matlab.mathworks.com 10 Minutes to pand Turn websites into. G knn algorithm-Go... IApps Getting Started Imported From Fire... THE SCRAPINGHUB. seaborn statistical. The Ultimate Pytho.. APPS ? O Shivani Mohan Search Documentation HOME PLOTS EDITOR PUBLISH FILE VERSIONS Run Section Go To Run and Advance Advance Save Find Files Find Breakpoints Rur New FILE EDIT NAVIGATE BREAKPOINTS RUN MATLAB Drive: sports Stats.m + function stats - sportsstats (stats, cutoff) appending new column after last column stats(:, 2) stats(, end+1) stats(, 2)stats 3) stats (, 3) will give average total yards per game 5 removing all teams with total penalties greater than given cutoff stats(stats (, 5)> cutoff, :) = [1 this will delete the rows where cutoff. :) []; stats(stats(. E 11 deleting column 4 from the matrix 12 1: stats(, 4) - [); 14 Sortrows will sort the ro sed on column 1 in descending order = sortrows (stats, ** descend"); 17 finding the number of rows, is used when we don't require that output 18 [size_row ] - size(stats) 19 20 finding the half of number of rows rounded to positive infinity size row ceil(size row 21 2); 22 finding the upper half of the matrix stats stats (1:size_row, :); end 25 26 COMMAND WINDOW
MATLAB Online R2019a + C https://matlab.mathworks.com THE SCRAPINGHUB.. Getting Started Imported From Fire... Turn websites into. G knn algorithm-Go... 10 Minutes to pand.. The Ultimate Pytho Apps seaborn: statistical. ? O Search Documentation Q Shivani Mohan HOME PLOTS APPS Community ? Upload Feedback Download Find Fies New New New Import Data Clear Workspace Favorites Show Clear Layout Preferences Add-Ons Hel Script Live Script History Commands Learn MATLAB FILE VARIABLE CODE ENVIRONMENT RESOURCES >MATLAB Drive CURRENT FOLDER WORKSPACE >stats1 NAME Name stats1= VALUE SIZE CLASS 378.0000 111 .0000 Published (my site) 26.8000 90.3000 313.0000 cutoff 105 1x1 double appendSumQ1.m 25.1000 126.300e newstats [26.3000,12. newStats1 [26.3000, 12. newstats2 3x5 double 236.3000 333.0000 105.eeee 2x5 double 20.3eee 103.8000 223.5000 325.ee0e 94.0000 avq totalQ3.m 2x5 double 26.3eee 121.10ee 222.8000 331.0000 97.e0ee highLowQ2.m 3x5 double stats2 stats 4x5 double 4 5 double myRand.m stats2 stats1 4x5 double 4*5 douple sportsStats.m 90.300e 111.eeee 26.8000 313.0000 378,0000 stats2 6x5 double 6x5 double 25.1ee0 126.3000 236.3000 333.eeee 105.00ee 20.3eee 103.800e 223.5000 325.eee0 94,00ee 26,3000 121.1800 222.8000 331.0000 97.000e 26.8000 126.30ee 223.5080 331.0000 93.eeee 378.ee00 90.ee00 25.1e00 103.8000 222.8000 >cutoff cutoff sportsStats ( stats1, cutoff) newStats1 newStats1 - 26.3eee 121.1000 222.8000 97.eeee 343.9000 25.1eee 126.300e newStats2 sportsStats (stats2, cutoff) 236.3000 1es.eeee 362.6000 newStats2 = 14
MATLAB Online R2019a + C https://matlab.mathworks.com THE SCRAPINGHUB.. Getting Started Imported From Fire... Turn websites into. G knn algorithm-Go... 10 Minutes to pand.. The Ultimate Pytho Apps seaborn: statistical. ? O Search Documentation Q Shivani Mohan HOME PLOTS APPS Community ? Upload Feedback Download Find Fies New New New Import Data Workspace Clear Favorites Show Clear Layout Preferences Add-Ons Hel Script Live Script History Commands Learn MATLAB FILE VARIABLE CODE ENVIRONMENT RESOURCES MATLAB Drive 25.1e00 126.3000 236.3000 333.0000 105.eeee WORKSPACE CURRENT FOLDER 20,3e0e 103.800e 223.5000 325.eeee 94.000e NAME Name VALUE SIZE CLASS 26.3eee 121.100e 222.8000 331.ee00 97.e0ee Published (my site) cutoff 105 1x1 double stats2 appendSumQ1.m newStats [26.3000,12. newStats1 [26.3000, 12. newstats2 3x5 double 2x5 double stats2 - avq totalQ3.m 2x5 double 5.8eee 90.3000 313.0000 378.0000 111.0000 highLowQ2.m 3x5 double 25.1e00 236.3000 333.ee0e 126.3006 105.e00e stats 4x5 double 4 5 double myRand.m 20.3eee 103.8000 223.5000 325.0e00 94.000e stats1 4x5 double 4*5 douple 26.3000 121.100e 222.8000 331.0000 97.e00e sportsStats.m stats2 6x5 double 6x5 double 26.8000 126.3000 223.5008 331.0000 93.eeee 103.8000 222.8000 378.e000 25.1eee 98.e00e cutoff cutoff 105 >newStats1 sportsStats (stats1, cutoff) newstats1 97.eee0 343.9000 26.3ee0 121.1000 222.8000 126.30e0 236.3000 25.10ee 105.eeee 362.6000 newStats2 sportsStats (stats2, cutoff) newStats2 = 26.8e00 126.3000 223,5000 93.0000 349.8000 26.3eee 121.100e 222.800e 97.ee0e 343.900e 25.1e00 126.300e 236.3000 105.eeee 362.60ee >> 14