Plot not displaying x axis correctly?

20 views (last 30 days)
Charles Amacker
Charles Amacker on 23 Nov 2020
Commented: dpb on 23 Nov 2020
Hello, I am making a function that creates a y value for a range of x values, say -7 to 7. I enter in x = (-7:7), put it through the function, and get values for Y. but then, when I plot it, the X axis is labeled according to column rather than value, as in the axis displays 0 through 15 rather than -7 to 7. how do I fix this?

Accepted Answer

dpb
dpb on 23 Nov 2020
Show us code to prove it, but, from the symptom described you wrote something like:
x=-7:7;
y=yourfunction(x);
plot(y)
which would display what you described (and have done precisely what you told MATLAB to do). With no x passed to it, plot doesn't know anything at all about the fact you defined x somewhere else; all it can do is use what it was given.
plot(x,y)
is the correct syntax.
HINT: Read the documentation before crying wolf! It'll be faster most of the time than waiting for somebody here to see and answer. :)
  2 Comments
Charles Amacker
Charles Amacker on 23 Nov 2020
Thank you, I was just using the plot function at the toolbar and wasnt entering any syntax at all. Entering that custom syntax helped. Thanks again!
dpb
dpb on 23 Nov 2020
I never use any of that stuff so dunno what it would take to add the x variable...but if it's a "just plot y" button, then the same thing would be true--it wouldn't know anything about what to pass to plot() for the x variable without being told somehow.

Sign in to comment.

More Answers (0)

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!