What errors can be found on this script?
Mostra commenti meno recenti
% Given data: Study hours and corresponding exam scores
study_hours = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21];
exam_scores = [50, 55, 60, 65, 72, 78, 83, 87, 90, 94, 96];
% Step 1: Create a scatter plot
% Use the scatter function to plot study_hours vs. exam_scores
scatter(study_hours, exam_scores) % <-- Modify this to customize the markers
% Step 2: Label the axes
% Use xlabel('text') and ylabel('text') to describe the data
xlabel('Study Hours per Week') % <-- Fill in the x-axis label
ylabel('Exam Score (%)') % <-- Fill in the y-axis label
% Step 3: Add a title
% Use the title function to describe the relationship
title('Relationship Between Study Hours and Exam Scores') % <-- Fill in an appropriate title
% Step 4: Customize marker style, size, and color
% Modify scatter to change marker shape, size, and color
% Example: scatter(x, y, size, 'color', 'filled')
% Uncomment and modify the line below
scatter(study_hours, exam_scores, 50, 'b', 'filled')
% Step 5: Enable the grid
% Uncomment the line below to turn on the grid
grid on
% Step 6: Add a legend
% Use the legend function to describe the data points
legend('Student Data') % <-- Fill in an appropriate legend
3 Commenti
Steven Lord
il 6 Mag 2026 alle 12:26
It seems to run perfectly well on MATLAB Answers. What leads you to believe there are errors in this script?
So, if we're nit-picking, one notes that the code comment (instructor-provided instructions?) states
% Use the scatter function to plot study_hours vs. exam_scores
but the plot is exam_scores vs study_hours, maybe?
Although it is more logical as shown, granted, it doesn't match the comment...of course, then the axis labels would be reversed, too. But, as @Steven Lord notes, it certainly runs as is. One enhancement is that one might use the 'Location' parameter on the legend to move it where it doesn't occlude the last data point...
% Given data: Study hours and corresponding exam scores
study_hours = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21];
exam_scores = [50, 55, 60, 65, 72, 78, 83, 87, 90, 94, 96];
% Step 1: Create a scatter plot
% Use the scatter function to plot study_hours vs. exam_scores
scatter(exam_scores,study_hours, 50, 'b', 'filled')
ylabel('Study Hours per Week') % <-- Fill in the x-axis label
xlabel('Exam Score (%)') % <-- Fill in the y-axis label
title('Study Hours vs Exam Scores')
grid on
box on
legend('Student Data','location','best')
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


