Plotting using the Bar Function

8 views (last 30 days)
Calil
Calil on 27 Aug 2022
Edited: dpb on 30 Aug 2022
I'm trying to plot a bar function in matlab. but it states that my y1 variable is incorrect. Can somebody please tell the error in my syntax?
  2 Comments
Steven Lord
Steven Lord on 27 Aug 2022
Please post the full and exact text of the message you receive from the grader. Knowing exactly what it suggests is incorrect may be useful in determining how to correct the problem.
If I had to guess I'd say it was complaining that you haven't added the legend etc. as requested in the sentence starting with "Be sure" but with the message I probably wouldn't have to guess.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 27 Aug 2022
Your code seemed to work for me. What error did it give you? Reply after you read this:
x = linspace(0, 10, 100);
y1 = exp((1/2) .* x) .* sin(2 * x);
bar(x, y1)
grid on;
title('My Homework')
xlabel('x');
ylabel('y');
legend
  1 Comment
Image Analyst
Image Analyst on 27 Aug 2022
What is "it"? Is it MATLAB? Or is it some kind of automated grader program like @dpb mentioned? He might be right that the grader might look for all the requested functions and look for specific variable names, like y instead of y1. So try
x = linspace(0, 10, 100);
y = exp((1/2) .* x) .* sin(2 * x);
bar(x, y)
grid on;
title('My Homework')
xlabel('x');
ylabel('y');
legend
If it's still not working show us EXACTLY what "it" is reporting. We need ALL the error text, not just a paraphrasing of it or a snippet from it.

Sign in to comment.


Cris LaPierre
Cris LaPierre on 28 Aug 2022
Edited: Cris LaPierre on 28 Aug 2022
The error you are getting from Grader is that the values of y1 are incorrect (if you were using the wrong variable name, the error would istead tell you the solution was expected to have a variable named 'y1'). This was determined by comparing the values of your variable with those generated by the instructor's solution (with some tolerance applied). So it is not that your code has an error, it is that you are not getting the expected result.
Where the error is not obvious, you may consider reaching out to your instructor if you think there is an error in the grading. You can do so by following the steps in this Answer and sending the solution id along with an explanation to your teacher.
  11 Comments
dpb
dpb on 30 Aug 2022
Edited: dpb on 30 Aug 2022
Ah, so! I had presumed just student highlighted comments; didn't understand there being such a template.
Makes sense, other than the choice by the instructor of the variable name...and that the answer was judged to be wrong for a most inexplicable reason (again, only from what we've been able to see, of course).
Thanks for the tutorial, Cris; much appreciated and I have a lot better idea of how Grader functions that, as noted before, is bound to help later Q? responses...

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!