Problem 44952. Find MPG of Lightest Cars
Mayla
el 10 de Sept. de 2023
Actividad más reciente Respuesta de Walter Roberson
a las el 24 de Oct. de 2023
That's the question:
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.
I wrote this code and the resulting column vector has the right values but it doesn't pass the tests. What's wrong?
function mpg = sort_cars(N)
load cars.mat
sorted=sortrows(cars,4)
mpg = sorted(1:N,2)
end
11 Comentarios
Tiempo descendenteHello Mayla,
The reason your code does not pass the test suite is because the variable mpg in your code is of Table data type, whereas the question expects the answer in Numeric data type.
This will be helpful - https://in.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html
Also, I would suggest you to check the assert() call while solving problems in Cody to see what and which type of output is expected.
Inicie sesión para participar