What errors can be found on this script?

% 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
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?
dpb
dpb il 6 Mag 2026 alle 13:15
Modificato: dpb il 6 Mag 2026 alle 13:35
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...
dpb
dpb circa 13 ore fa
Modificato: dpb circa 9 ore fa
% 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')

Accedi per commentare.

 Risposta accettata

Walter Roberson
Walter Roberson circa 21 ore fa
Modificato: Walter Roberson circa 21 ore fa
scatter(study_hours, exam_scores) % <-- Modify this to customize the markers
You failed to customize the markers.
The near-linear relationship between study hours and exam score is a bit suspicious. What do the numbers represent anyhow?
  • single person starting at studying one hour per week, taking a particular exam, rising to 3 hours per week, then taking the same exam, and so on, until they are eventually studying 21 hours per week on a single course but still taking the same exam? Are they not getting any feedback on the exam results that might allow them to use the cumulative knowledge? I would put it to you that in such a situation, the rising scores instead reflect slow accumulation of knowledge of the same exam, by someone who is not especially competent
  • single person starting at studying one hour per week, taking an exam, rising to 3 hours per week, then taking a different exam, rising to 5 hours per week, taking yet another exam, and so on? If so then where is the normal variation we would expect from some exams being harder than others?
  • single person studying 13 hours the first week, then taking an exam, then studying 21 hours the second week, then taking a different exam, then studying 3 hours the third week, taking a third exam, and so on? If so then you would expect the order of study timings to be important, as studying 21 hours would be expected to have benefits that carry over to the following 3 hour studying
  • multiple people studying, one on a 1 hour a week plan, another on a 3 hour a week plan and so on, all taking the same exam together? If so then due to variations in ability you would expect more variation in outcome, not a nearly-linear increase in scores

3 Commenti

dpb
dpb circa 7 ore fa
Modificato: dpb circa 7 ore fa
"You failed to customize the markers...."
The original posting showed
% 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')
That's a confusing instruction to me, too...since all the pieces were outlined by steps; I also interpreted the comment as information, not instruction since Step 4 is where is told to do so.
So appears to me other than the (probably unintended) confusion of which was to be interpreted as the independent variable, the instructions were followed step by step as requested. Only the instructor actually knows for sure what was intended, I think.
As for a meaning, I'd posit
  • Not so subtle hint that more effort invested pays off in better results with purely arbitrary numbers. <grin>
I see a different problem.
You have two different set of plotting instructions, with no "hold on". When you call the second scatter() without hold being on, the axes would be automatically cleared -- removing the axis labels. So the result you would get in the command window would not have any axis labels.
If you ran the code in LiveScript then two different plots would show up, the first with axes labels and the second without axes labels.
dpb
dpb circa 6 ore fa
Modificato: dpb circa 6 ore fa
I notieced that as well, Walter, and indeed, the second plot is bare of annotation ... excepting that's what the instructions said.
Another case where it isn't known precisely what kind of instructor is -- although one could presume the intent would be for the student to add stuff on own, I've had at least one that would have marked off for not following the instructions to have inserted a hold on snce was not specifically in the rules/steps provided. It can be a no win situation...
If we're allowed flexibility to achieve same ends in steps but in the final figure
hSC=scatter(study_hours, exam_scores); % original bare bones scatter, save handle
% Step 4: Customize marker style, size, and color
% Modify scatter to change marker shape, size, and color
set(hSC,'MarkerFaceColor','r','SizeData',50) % set face color and marker size
since the numeric size and 'filled' arguments map to the above internal scatter object properties/values. But, that also presumes something about the instructor and the student going beyond the explicit points covered in lecture and assignments.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange

Tag

Richiesto:

il 6 Mag 2026 alle 11:43

Modificato:

dpb
il 7 Mag 2026 alle 15:40

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by