Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with fixing this code. Everytime i run the code an error comes up for step 2 . Step one has the imported

I need help with fixing this code. Everytime i run the code an error comes up for step 2. Step one has the imported datas that i need and its supposed to generate a two graphs. The two graphs that i need are shown in the
picture.
% Step 1: Import the two datasets and combine them into one global datasetdata1= importdata('2021_Cars_Aggregated.csv'); % Dataset is stored in 'download file'data2= importdata('2021.Vans_Aggregated.csv'); % The second dataset is stored in 'download file'% Combine the datasetscombined_data =[data1; data2];% Step 2: Bar chart showing how many cars use distinct fuel typesfuel_types = unique(combined_data(:,1));fuel_type_counts = histcounts(combined_data(:,2), fuel_types);figure;bar(fuel_types, fuel_type_counts);title('Number of Cars by Fuel Type');xlabel('Fuel Type');ylabel('Number of Cars');% Step 3: Create a scatter plot showing the weighted CO2 Percentage for each carsorted_combined_data = sortrows(combined_data, 1); % Sort by car manufacturerweighted_CO2_percentage = sorted_combined_data(:, end); % Weighted CO2 percentage is in the last column% Plot scatter plotfigure;scatter(1:numel(weighted_CO2_percentage), weighted_CO2_percentage);hold on;% Fit a polynomial of degree 2p = polyfit(1:numel(weighted_CO2_percentage), weighted_CO2_percentage, 2);x_values =1:numel(weighted_CO2_percentage);y_fit = polyval(p, x_values);plot(x_values, y_fit, 'r--', 'LineWidth', 2);title('Weighted CO2 Percentage for Each Car');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 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

More Books

Students also viewed these Databases questions

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago