Highlight Region of Sine Graph

I have a sine graph and I want to highlight all along the x-axis and just the [-1,1] region on the y-axis. Is this possible?
This is my code and I would like the bounds between [-1,1] on the y-axis to be shaded some color all along the x-axis. The whole area, not just the peaks and valleys.

 Accepted Answer

% Do you want this?
x=linspace(0,2*pi,101);
y=sin(x);
area(x,y)

5 Comments

This is my code and on the graph, I would like the bounds between [-1,1] for the y-axis shaded some color all along the x-axis. Sorry if I wasn't clear. I would like the shaded region to be all across and nt just where the peaks and valleys are. Thank you.
x=linspace(-5*pi,5*pi,100);
KP1=(6*(sin(x)/(x)))+cos(x);
for c=1:100
KP1(c)=(6*(sin(x(c))/(x(c))))+cos(x(c));
end
plot(x,KP1)
This is the whole plot:
x=linspace(-5*pi,5*pi,101);
KP1=(6*(sin(x)./(x)))+cos(x);
plot(x,KP1)
Now what do you want to do?
Thanks for your help and patience. I would two straight lines that pass all along the x-axis at -1 and 1 on the y-axis. If the space between these two lines could be filled as well.
This is the next step:
x=linspace(-5*pi,5*pi,101);
KP1=(6*(sin(x)./(x)))+cos(x);
hold on;
plot(x,KP1)
plot([-5*pi,5*pi],[-1,-1],'r');
plot([-5*pi,5*pi],[1,1],'r');
Amazing! Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots 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!