Problem 44952. Find MPG of Lightest Cars
The file cars.mat contains a table named cars with variables Model, MPG, Horsepower, Weight, and Acceleration for several classic cars.
Load the MAT-file. Given an integer N, calculate the output variable mpg.
Output mpg should contain the MPG of the top N lightest cars (by Weight) in a column vector.
Solution Stats
Problem Comments
-
40 Comments
Show
37 older comments
梓斌
on 22 Nov 2024
Notes:
1.In the function, you need write this code "load cars.mat;". Then, you have a table variable:cars
2.The return values mpg is a double variable, not table variable.
Xinghang
on 19 Jan 2025
should understand the use of table.
El
on 26 Apr 2025 at 17:05
Keep in mind that when you load cars.. you'll need to extract the table from what you loaded...
i.e.
cars = load('cars.mat');
cars = cars.cars;
Solution Comments
Show commentsGroup

MATLAB Onramp Practice
- 15 Problems
- 4632 Finishers
- Times 2 - START HERE
- Calculate Amount of Cake Frosting
- Convert from Fahrenheit to Celsius
- Find the Oldest Person in a Room
- Verify Law of Large Numbers
- Solve a System of Linear Equations
- Calculate a Damped Sinusoid
- Plot Damped Sinusoid
- Calculate BMI
- Crop an Image
- Find the Best Hotels
- Find MPG of Lightest Cars
- Calculate Inner Product
- Rescale Scores
- Longest run of consecutive numbers
Problem Recent Solvers6899
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!