function mpg = sort_cars(N)
load cars.mat
sorted = sortrows (cars,4);
mpg = sorted(1:N,2);
mpg{:,:}
end
Gives the correct output yet assertion failed. Why?
Test | Status | Code Input and Output |
---|---|---|
1 | Fail |
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
ans =
35.0000
31.0000
39.1000
35.1000
31.0000
|
2 | Fail |
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
ans =
33.0000
29.5000
26.0000
29.0000
38.0000
32.0000
|
Find the sum of the elements in the "second" diagonal
994 Solvers
2334 Solvers
429 Solvers
306 Solvers
Find the Oldest Person in a Room
5103 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!