I dont understand why this function is not working.
조회 수: 5 (최근 30일)
이전 댓글 표시
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.
please help mw with the code. this is not producing correct answer.
function mpg = sort_cars(N)
load('cars.mat')
S=table(cars)
cars=sortrows(S,'Weight','ascending')
mpg =cars(1:N,'MPG');
end
댓글 수: 6
RITISH
2022년 12월 17일
@Sajjad Hossain what does the 2 means in k=car(1:N,2) ? Does it mean 2nd column of car which isnt there and how it is related to mpg.
Walter Roberson
2022년 12월 17일
It does mean the second column of car, which should have four columns in context
채택된 답변
Walter Roberson
2020년 4월 27일
S=table(cars)
That will not create any variable in table S that is named "Weight'.
If cars is already a table, then the result of that is that S would be a table with a single variable named cars and that single variable would be a table.
If cars is a numeric array, then you would want to use array2table() and you would want to pass in a 'VariableNames' option listing the variable names.
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!