Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

so this code should generate 5 graphs but it only generates 4 graphs and these errors keeps coming up that you see on the picture.

so this code should generate 5 graphs but it only generates 4 graphs and these errors keeps coming up that you see on the picture. I need figure 5 graph to come up. Could you please amek sure that all the errors are gone and all 5 graphs that includes figure for come up. Please use matlab to fix the code.
clearclc%% EGME 205: Digital Computation Project%% Part 1: Randomly Generated Data% Step 1: First we need a date vector from January 1st,2024 to December 31st,2024start_date = datetime(2024,1,1);end_date = datetime(2024,12,31);date_vector = start_date:end_date;% Step 2: Trying to find associated days of the weekdays_of_week = day(date_vector, 'name');% Step 3: Here is how to make a random temperature vectortemperature_max =120;temperature_min =55;temperature_vector =(temperature_max - temperature_min)* rand(size(date_vector))+ temperature_min;% Step 4: Creating a string for the weekend daysweekend_days = string(date_vector(weekday(date_vector)==1| weekday(date_vector)==7));% Step 5: Development of more substance to the report%(a) Here is a linear plot for weekends in which the temperature is over 100weekend_indices = find(temperature_vector >100 & (weekday(date_vector)==1| weekday(date_vector)==7));figure;plot(date_vector(weekend_indices), temperature_vector(weekend_indices),'-o');title('Weekend Temperatures over 100');xlabel('Date');ylabel('Temperature');%(b) This section is a bar plot showing how many times the temperature is below 85 in each monthmonths = unique(month(date_vector));temperature_below_85_count = zeros(size(months));for i =1:numel(months)month_indices = find(month(date_vector)== months(i));temperature_below_85_count(i)= sum(temperature_vector(month_indices)85);endfigure;bar(months, temperature_below_85_count);title('Count of Days with Temperature Below 85 in Each Month');xlabel('Month');ylabel('Count');%(c) Here we have two linear plots showing the maximum and minimum temperature in each monthmax_temperature_monthly = accumarray(month(date_vector)', temperature_vector', [], @max);min_temperature_monthly = accumarray(month(date_vector)', temperature_vector', [], @min);figure;plot(months, max_temperature_monthly, '-o', 'DisplayName', 'Max Temperature');hold on;plot(months, min_temperature_monthly, '-o', 'DisplayName', 'Min Temperature');hold off;title('Monthly Maximum and Minimum Temperatures');xlabel('Month');ylabel('Temperature');legend('Location', 'best');%% 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% Combine the datasetscombined_data =[data1; data2];% Step 2a: Create a bar chart showing how many cars use distinct fuel types% Preprocess data: remove missing or empty values from 'FuelType' columnvalid_indices = ~ismissing(combined_data.FuelType) & ~strcmp(combined_data.FuelType, '');% Filter the combined data based on valid indicesvalid_fuel_data = combined_data(valid_indices, :);% Get unique fuel types and count occurrences[fuel_types, ~, fuel_type_indices]= unique(valid_fuel_data.FuelType);fuel_counts = histcounts(fuel_type_indices, 1:numel(fuel_types)+1);% 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 accordingly% Plot scatter plotfigure;scatter(1:numel(sorted_CO2_percentage), sorted_CO2_percentage);hold on;% Fit a polynomial of degree 2x_values =(1:numel(sorted_CO2_percentage))'; % Ensure x_values is a column vectorsorted_CO2_percentage = sorted_CO2_percentage(:); % Convert to column vectorp = polyfit(x_values, sorted_CO2_percentage, 2);y_fit = polyval(p, x_values);plot(x_values, y_fit, 'r--', 'LineWidth', 2);title('Weighted CO2 Percentage for Each Car (Sorted by Manufacturer)');xlabel('Car (Sorted by Manufacturer)');ylabel('Weighted CO2 Percentage');legend('Data Points', 'Line of Best Fit (Degree 2)', 'Location', 'best');hold off;
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions