Cody

Problem 44952. Find MPG of Lightest Cars

Solution 3169516

Submitted on 12 Oct 2020 by Rao Fu
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
N = 5 load(fullfile(matlabroot, 'toolbox/stats/statsdemos', 'carbig.mat')); Model = strtrim(string(Model)); cars = table(Model, MPG, Horsepower, Weight, Acceleration); save cars.mat cars assert(isequal(sort_cars(N),[35; 31; 39.1; 35.1; 31]));

N = 5 cars = 406×5 string array "datsun 1200" "35" "69" "1613" "18" "toyota corona" "31" "52" "1649" "16.5" "toyota starlet" "39.1" "58" "1755" "16.9" "honda civic 1300" "35.1" "60" "1760" "16.1" "toyota corolla 1200" "31" "65" "1773" "19" "honda civic cvcc" "33" "53" "1795" "17.5" "honda civic" "33" "53" "1795" "17.4" "ford fiesta" "36.1" "66" "1800" "14.4" "honda civic cvcc" "36.1" "60" "1800" "16.4" "volkswagen rabbit" "29.5" "71" "1825" "12.2" "renault 5 gtl" "36" "58" "1825" "18.6" "volkswagen model 111" "27" "60" "1834" "19" "volkswagen 1131 deluxe sedan" "26" "46" "1835" "20.5" "renault lecar deluxe" "40.9" <missing> "1835" "17.3" "toyota corolla 1200" "32" "65" "1836" "21" "volkswagen rabbit" "29.8" "62" "1845" "15.3" "honda civic 1500 gl" "44.6" "67" "1850" "13.8" "fiat 128" "29" "49" "1867" "19.5" "plymouth champ" "39" "64" "1875" "16.4" "dodge colt hatchback custom" "35.7" "80" "1915" "14.4" "volkswagen rabbit custom" "31.9" "71" "1925" "14" "volkswagen rabbit" "29" "70" "1937" "14" "volkswagen rabbit" "29" "70" "1937" "14.2" "volkswagen rabbit custom" "29" "78" "1940" "14.5" "datsun f-10 hatchback" "33.5" "70" "1945" "16.8" "volkswagen super beetle" "26" "46" "1950" "21" "datsun b210" "31" "67" "1950" "19" "plymouth cricket" "26" "70" "1955" "20.5" "volkswagen dasher" "26" "67" "1963" "15.5" "honda civic" "38" "67" "1965" "15" "honda civic (auto)" "32" "67" "1965" "15.7" "toyota corolla tercel" "38.1" "60" "1968" "18.8" "mazda glc custom" "31" "68" "1970" "17.6" "mazda glc deluxe" "34.1" "65" "1975" "15.2" "datsun 210 mpg" "37" "65" "1975" "19.4" "volkswagen super beetle 117" <missing> "48" "1978" "20" "volkswagen rabbit l" "36" "74" "1980" "15.3" "subaru dl" "30" "67" "1985" "16.4" "volkswagen rabbit custom di…" "43.1" "48" "1985" "21.5" "mazda glc deluxe" "32.8" "52" "1985" "19.4" "mazda glc 4" "34.1" "68" "1985" "16" "datsun b-210" "32" "70" "1990" "17" "volkswagen scirocco" "31.5" "71" "1990" "14.9" "datsun 310 gx" "38" "67" "1995" "16.2" "fiat x1.9" "31" "67" "2000" "16" "datsun 710" "32" "61" "2003" "19" "datsun 310" "37.2" "65" "2019" "16.4" "datsun 210" "31.8" "65" "2020" "19.2" "mazda glc custom l" "37" "68" "2025" "18.2" "chevrolet chevette" "29" "52" "2035" "22.2" "honda accord cvcc" "31.5" "68" "2045" "18.5" "ford escort 4w" "34.4" "65" "2045" "16.2" "ford pinto" "25" <missing> "2046" "19" "toyota tercel" "37.7" "62" "2050" "17.3" "chevrolet chevette" "30.5" "63" "2051" "17" "fiat 124b" "30" "76" "2065" "14.5" "subaru" "32.3" "67" "2065" "17.8" "datsun b210 gx" "39.4" "70" "2070" "18.6" "peugeot 304" "30" "70" "2074" "19.5" "dodge colt m/m" "33.5" "83" "2075" "15.9" "volkswagen rabbit c (diesel)" "44.3" "48" "2085" "21.7" "toyota corolla 1600 (sw)" "27" "88" "2100" "16.5" "fiat 128" "24" "75" "2108" "15.5" "mazda glc" "46.6" "65" "2110" "17.9" "datsun 210" "40.8" "65" "2110" "19.2" "chevrolet chevette" "32.1" "70" "2120" "15.5" "opel 1900" "28" "90" "2123" "14" "mazda rx3" "18" "90" "2124" "13.5" "dodge colt" "28" "75" "2125" "14.5" "plymouth horizon miser" "38" "63" "2125" "14.7" "mercury lynx l" "36" "70" "2125" "17.3" "dodge colt hardtop" "25" "80" "2126" "17" "datsun pl510" "27" "88" "2130" "14.5" "datsun pl510" "27" "88" "2130" "14.5" "fiat strada custom" "37.3" "69" "2130" "14.7" "volkswagen pickup" "44" "52" "2130" "24.6" "honda accord lx" "29.5" "68" "2135" "16.6" "volkswagen rabbit" "41.5" "76" "2144" "14.7" "subaru dl" "33.8" "67" "2145" "18" "plymouth horizon tc3" "34.5" "70" "2150" "14.9" "toyota corolla" "28" "75" "2155" "16.4" "buick opel isuzu deluxe" "30" "80" "2155" "14.8" "chevrolet chevette" "30" "68" "2155" "16.5" "opel manta" "24" "75" "2158" "15.5" "nissan stanza xe" "36" "88" "2160" "14.5" "dodge colt (sw)" "28" "80" "2164" "15" "chevrolet woody" "24.5" "60" "2164" "22.1" "toyota corolla" "29" "75" "2171" "16" "audi 4000" "34.3" "78" "2188" "15.8" "renault 12 (sw)" "26" "69" "2189" "18" "volkswagen dasher" "30.5" "78" "2190" "14.1" "volkswagen jetta" "33" "74" "2190" "14.2" "plymouth horizon" "34.2" "70" "2200" "13.2" "renault 12tl" "27" "83" "2202" "15.3" "honda accord" "36" "75" "2205" "14.5" "honda prelude" "33.7" "75" "2210" "14.4" "plymouth horizon 4" "34.7" "63" "2215" "14.9" "audi fox" "29" "83" "2219" "16.5" "mercury capri 2000" "23" "86" "2220" "14" "opel 1900" "25" "81" "2220" "16.9" "volkswagen dasher" "25" "71" "2223" "16.5" "ford pinto runabout" "21" "86" "2226" "16.5" "toyota corona" "25" "95" "2228" "14" "dodge omni" "30.9" "75" "2230" "14.5" "bmw 2002" "26" "113" "2234" "12.5" "toyota corolla" "34" "70" "2245" "16.9" "fiat 124 tc" "26" "75" "2246" "14" "volkswagen type 3" "23" "54" "2254" "23.5" "dodge colt" "26" "79" "2255" "17.7" "chevrolet vega 2300" "28" "90" "2264" "15.5" "fiat 124 sport coupe" "26" "90" "2265" "15.5" "toyota corolla liftback" "26" "75" "2265" "18.2" "toyota corolla" "32.2" "75" "2265" "15.2" "toyota corona hardtop" "24" "95" "2278" "15.5" "toyota carina" "20" "88" "2279" "19" "datsun 510 (sw)" "28" "92" "2288" "17" "honda accord" "32.4" "72" "2290" "17" "dodge rampage" "32" "84" "2295" "11.6" "opel manta" "26" "78" "2300" "14.5" "plymouth arrow gs" "25.5" "96" "2300" "15.5" "datsun 510" "27.2" "97" "2300" "14.7" "ford pinto" ...

2   Pass
N = 6 load(fullfile(matlabroot, 'toolbox/stats/statsdemos', 'carsmall.mat')); Model = strtrim(string(Model)); cars = table(Model, MPG, Horsepower, Weight, Acceleration); save cars.mat cars assert(isequal(sort_cars(N),[33; 29.5; 26; 29; 38; 32]));

N = 6 cars = 100×5 string array "honda civic" "33" "53" "1795" "17.4" "volkswagen rabbit" "29.5" "71" "1825" "12.2" "volkswagen 1131 deluxe sedan" "26" "46" "1835" "20.5" "volkswagen rabbit" "29" "70" "1937" "14.2" "honda civic" "38" "67" "1965" "15" "honda civic (auto)" "32" "67" "1965" "15.7" "mazda glc custom" "31" "68" "1970" "17.6" "volkswagen rabbit l" "36" "74" "1980" "15.3" "datsun b-210" "32" "70" "1990" "17" "datsun 310 gx" "38" "67" "1995" "16.2" "mazda glc custom l" "37" "68" "2025" "18.2" "chevrolet chevette" "29" "52" "2035" "22.2" "plymouth horizon miser" "38" "63" "2125" "14.7" "mercury lynx l" "36" "70" "2125" "17.3" "datsun pl510" "27" "88" "2130" "14.5" "volkswagen pickup" "44" "52" "2130" "24.6" "toyota corolla" "28" "75" "2155" "16.4" "nissan stanza xe" "36" "88" "2160" "14.5" "chevrolet woody" "24.5" "60" "2164" "22.1" "renault 12tl" "27" "83" "2202" "15.3" "honda accord" "36" "75" "2205" "14.5" "opel 1900" "25" "81" "2220" "16.9" "bmw 2002" "26" "113" "2234" "12.5" "toyota corolla" "34" "70" "2245" "16.9" "dodge colt" "26" "79" "2255" "17.7" "dodge rampage" "32" "84" "2295" "11.6" "dodge charger 2.2" "36" "84" "2370" "13" "toyota corona mark ii" "24" "95" "2372" "15" "saab 99e" "25" "95" "2375" "17.5" "chevrolet cavalier 2-door" "34" "88" "2395" "18" "audi 100 ls" "24" "90" "2430" "14.5" "fiat 131" "28" "86" "2464" "15.5" "dodge aries se" "29" "84" "2525" "16" "ford pinto" "26.5" "72" "2565" "13.6" "ford capri ii" "25" "92" "2572" "14.9" "pontiac j2000 se hatchback" "31" "85" "2575" "16.2" "chrysler lebaron medallion" "26" "92" "2585" "14.5" "ford maverick" "21" "85" "2587" "16" "chevrolet cavalier" "28" "88" "2605" "19.6" "ford ranger" "28" "79" "2625" "18.6" "chevrolet cavalier wagon" "27" "88" "2640" "18.6" "amc gremlin" "21" "90" "2648" "15" "toyota celica gt" "32" "96" "2665" "13.9" "peugeot 504" "25" "87" "2672" "17.5" "chevrolet s-10" "31" "82" "2720" "19.4" "pontiac phoenix" "27" "90" "2735" "18" "amc hornet" "18" "97" "2774" "15.5" "ford mustang gl" "27" "86" "2790" "15.6" "plymouth duster" "22" "95" "2833" "15.5" "ford granada l" "22" "112" "2835" "14.7" "ford fairmont futura" "24" "92" "2865" "16.4" "toyota mark ii" "19" "108" "2930" "15.5" "buick century limited" "25" "110" "2945" "16.4" "chevrolet camaro" "27" "90" "2950" "17.3" "ford maverick" "24" "81" "3012" "17.6" "oldsmobile cutlass ciera (d…" "38" "85" "3015" "17" "amc concord dl" "23" <missing> "3035" "20.5" "amc hornet" "22.5" "90" "3085" "17.6" "buick estate wagon (sw)" "14" "225" "3086" "10" "citroen ds-21 pallas" <missing> "115" "3090" "17.5" "volvo 245" "20" "102" "3150" "15.7" "amc pacer d/l" "17.5" "95" "3193" "17.8" "plymouth valiant" "22" "100" "3233" "15.4" "peugeot 504" "19" "88" "3270" "21.9" "ford mustang boss 302" <missing> "140" "3353" "8" "chevrolet nova" "22" "105" "3353" "14.5" "amc rebel sst" "16" "150" "3433" "12" "plymouth satellite" "18" "150" "3436" "11" "ford torino" "17" "140" "3449" "10.5" "chevrolet chevelle malibu" "18" "130" "3504" "12" "dodge challenger se" "15" "170" "3563" "10" "ford granada ghia" "18" "78" "3574" "21" "plymouth 'cuda 340" "14" "160" "3609" "8" "pontiac ventura sj" "18.5" "110" "3645" "16.2" "dodge aspen se" "20" "100" "3651" "17.7" "buick skylark 320" "15" "165" "3693" "11.5" "dodge d100" "13" "150" "3755" "14" "chevrolet monte carlo" "15" "150" "3761" "9.5" "mercedes-benz 280s" "16.5" "120" "3820" "16.7" "amc ambassador dpl" "15" "190" "3850" "8.5" "amc rebel sst (sw)" <missing> "175" "3850" "11" "ford f108" "13" "130" "3870" "15" "plymouth volare premier v8" "13" "150" "3940" "13.2" "amc matador" "15.5" "120" "3962" "13.9" "ford torino (sw)" <missing> "153" "4034" "11" "chevrolet c10" "13" "145" "4055" "12" "chevrolet chevelle concours…" <missing> "165" "4142" "11.5" "plymouth satellite (sw)" <missing> "175" "4166" "10.5" "dodge coronet brougham" "16" "150" "4190" "13" "chevrolet chevelle malibu c…" "17.5" "140" "4215" "13" "ford gran torino" "14.5" "152" "4215" "12.8" "plymouth fury iii" "14" "215" "4312" "8.5" "ford galaxie 500" "15" "198" "4341" "10" "chevrolet impala" "14" "220" "4354" "9" "chevrolet c20" "10" "200" "4376" "15" "cadillac seville" "16.5" "180" "4380" "12.1" "dodge d200" "11" "210" "4382" "13.5" "pontiac catalina" "14" "225" "4425" "10" "ford f250" "10" "215" "4615" "14" "ih 1200d" "9" "193" "4732" "18.5" mpg = 33.0000 29.5000 26.0000 29.0000 38.0000 32.0000

Suggested Problems

More from this Author13

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!