Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please explain what is each part of this matlab code: % % part 2 % Step 1 : Import the two datasets and combine them
Please explain what is each part of this matlab code:
part Step : Import the two datasets and combine them into one global datasetdata readtableCarsAggregated.csv; Import the first datasetdata readtableVansAggregated.csv; Import the second datasetSet a fixed seed for reproducibilityseed ; Choose any integer value for the seedrngseed; Set the random number generator seed Sample data for Diesel and Petrol carscarPosition linspace; Assumed CO emissions for Diesel and PetrolCODiesel expcarPosition pi randn;COPetrol carPosition pi randn; Fit polynomial curves with a reduced degree of pDiesel polyfitcarPosition CODiesel, ;pPetrol polyfitcarPosition COPetrol, ; Generate points for best fit linesfitDiesel polyvalpDiesel carPositioncarPosition;fitPetrol polyvalpPetrol carPosition; Plotting the datafigure;hold on; Plot Diesel best fit lineplotcarPositioncarPosition fitDiesel, 'Color', 'LineWidth', ; Plot Petrol best fit lineplotcarPosition fitPetrol, 'Color', 'LineWidth', ; Petrol datascattercarPosition COPetrol, o 'MarkerEdgeColor', ; Blue for Petrol Diesel datascattercarPosition CODiesel, o 'MarkerEdgeColor', ; Orange for Diesel Customize the plotxlabelCar Position';ylabelCO Weighted Percentage';titleWeighted CO Emissions';xlim;ylim; Add a legend with custom nameslegendDiesel Best Fit', 'Petrol Best Fit', 'Petrol', 'Diesel'; Add grid linesgrid on;hold off; Combine the datasetscombineddata data; data; Step a: Create a bar chart showing how many cars use distinct fuel types Preprocess data: remove missing or empty values from 'FuelType' columnvalidindices ~ismissingcombineddata.FuelType & ~strcmpcombineddata.FuelType, ; Filter the combined data based on valid indicesvalidfueldata combineddatavalidindices, :; Get unique fuel types and count occurrencesfueltypes, ~ fueltypeindices uniquevalidfueldata.FuelType;fuelcounts histcountsfueltypeindices, :numelfueltypes; Plot the bar chartfigure;bar:numelfueltypes fuelcounts;titleNumber of Cars Using Distinct Fuel Types';xlabelFuel Type';ylabelNumber of Cars';xticks:numelfueltypes;xticklabelsfueltypes; Step b: Create a scatter plot showing the weighted CO Percentage for each carsortedmanufacturers, manufacturerindices sortcombineddata.Manufacturer; Sort manufacturers alphabeticallysortedCOpercentage combineddata.COPercentagemanufacturerindices; Sort CO Percentage accordinglySet a fixed seed for reproducibilityseed ; Choose any integer value for the seedrngseed; Set the random number generator seed Sample data for Diesel and Petrol carscarPosition linspace; Assumed CO emissions for Diesel and PetrolCODiesel expcarPosition pi randn;COPetrol carPosition pi randn; Fit polynomial curves with a reduced degree of pDiesel polyfitcarPosition CODiesel, ;pPetrol polyfitcarPosition COPetrol, ; Generate points for best fit linesfitDiesel polyvalpDiesel carPositioncarPosition;fitPetrol polyvalpPetrol carPosition; Plotting the datafigure;hold on;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started