Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please explain each step of this code and explain each part that has an % sign next to it . Give small explanations with each
Please explain each step of this code and explain each part that has an sign next to it Give small explanations with each step and each part that has the sign next to it
Step : First we need a date vector from January st to December ststartdate datetime;enddate datetime;datevector startdate:enddate; Step : Trying to find associated days of the weekdaysofweek daydatevector, 'name'; Step : Here is how to make a random temperature vectortemperaturemax ;temperaturemin ;temperaturevector temperaturemax temperaturemin randsizedatevector temperaturemin; Step : Creating a string for the weekend daysweekenddays stringdatevectorweekdaydatevector weekdaydatevector; Step : Development of more substance to the reporta Here is a linear plot for weekends in which the temperature is over weekendindices findtemperaturevector & weekdaydatevector weekdaydatevector;figure;plotdatevectorweekendindices temperaturevectorweekendindiceso;titleWeekend Temperatures over ;xlabelDate;ylabelTemperature;b This section is a bar plot showing how many times the temperature is below in each monthmonths uniquemonthdatevector;temperaturebelowcount zerossizemonths;for i :numelmonths monthindices findmonthdatevector monthsi; temperaturebelowcounti sumtemperaturevectormonthindices;endfigure;barmonths temperaturebelowcount;titleCount of Days with Temperature Below in Each Month';xlabelMonth;ylabelCount;c Here we have two linear plots showing the maximum and minimum temperature in each monthmaxtemperaturemonthly accumarraymonthdatevector temperaturevector', @max;mintemperaturemonthly accumarraymonthdatevector temperaturevector', @min;figure;plotmonths maxtemperaturemonthly, o 'DisplayName', 'Max Temperature';hold on;plotmonths mintemperaturemonthly, o 'DisplayName', 'Min Temperature';hold off;titleMonthly Maximum and Minimum Temperatures';xlabelMonth;ylabelTemperature;legendLocation 'best'; Part : Imported Data 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