Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please explain what is going on in each part of this code Thats on matlab % % Part 2 : Imported Data % Step 1

Please explain what is going on in each part of this code Thats on matlab
%% Part 2: Imported Data% Step 1: Import the two datasets and combine them into one global datasetdata1= readtable('2021_Cars_Aggregated.csv'); % Import the first datasetdata2= readtable('2021.Vans_Aggregated.csv'); % Import the second dataset% Set a fixed seed for reproducibilityseed =50;rng(seed);% Sample data for Diesel and Petrol carscarPosition = linspace(1,60,50);% Assumed CO2 emissions for Diesel and Petrol with modified randomness for spreadCO2Diesel =20+2* exp(-carPosition /60*2* pi)- randn(1,50)*3; % Increased randomness scaleCO2Petrol =18+2*(carPosition /60*2* pi).^0.3+ randn(1,50)*3; % Increased randomness scale% Fit polynomial curves with a reduced degree of 2pDiesel = polyfit(carPosition, CO2Diesel, 2);pPetrol = polyfit(carPosition, CO2Petrol, 2);% Generate points for best fit linesfitDiesel = polyval(pDiesel, carPosition(carPosition<50));fitPetrol = polyval(pPetrol, carPosition);% Plotting the datafigure; hold on;% Plot Diesel best fit lineplot(carPosition(carPosition<50), fitDiesel, 'Color', [1,0.5,0], 'LineWidth', 2);% Plot Petrol best fit lineplot(carPosition, fitPetrol, 'Color', [0.5,0,0.5], 'LineWidth', 1);% Petrol datascatter(carPosition, CO2Petrol, 'o', 'MarkerEdgeColor', [0,0.5,1]);% Diesel datascatter(carPosition, CO2Diesel, 'o', 'MarkerEdgeColor', [1,0.5,0]);% Customize the plotxlabel('Car Position');ylabel('CO2 Weighted Percentage');title('Weighted CO2 Emissions');xlim([160]);ylim([050]);yticks(0:10:50); % Setting Y-ticks to increment by 10slegend('Diesel Best Fit', 'Petrol Best Fit', 'Petrol', 'Diesel');grid on;hold off;% Plot the bar chartfigure;bar(1:numel(fuel_types), fuel_counts);title('Number of Cars Using Distinct Fuel Types');xlabel('Fuel Type');ylabel('Number of Cars');xticks(1:numel(fuel_types));xticklabels(fuel_types);% Step 2b: Create a scatter plot showing the weighted CO2 Percentage for each car[sorted_manufacturers, manufacturer_indices]= sort(combined_data.Manufacturer); % Sort manufacturers alphabeticallysorted_CO2_percentage = combined_data.CO2_Percentage(manufacturer_indices); % Sort CO2 Percentage accordinglySet a fixed seed for reproducibilityseed =50; % Choose any integer value for the seedrng(seed); % Set the random number generator seed% Sample data for Diesel and Petrol carscarPosition = linspace(1,60,50);% Assumed CO2 emissions for Diesel and PetrolCO2Diesel =20+2* exp(-carPosition /60*2* pi)- randn(1,50)*2;CO2Petrol =18+2*(carPosition /60*2* pi).^0.3+ randn(1,50)*2;% Fit polynomial curves with a reduced degree of 2pDiesel = polyfit(carPosition, CO2Diesel, 2);pPetrol = polyfit(carPosition, CO2Petrol, 2);% Generate points for best fit linesfitDiesel = polyval(pDiesel, carPosition(carPosition<50));fitPetrol = polyval(pPetrol, carPosition);% Plotting the datafigure;hold on,

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions