Shade areas between graphs

1 view (last 30 days)
I need to shade the areas of graph above y = 1 line and below y = -1 line. How can I do code for that.
Like this one.

Accepted Answer

Sudheer Bhimireddy
Sudheer Bhimireddy on 19 Oct 2020
Look at area() function in MATLAB. May be that helps with your code.
Below is an example:
x = -3*pi : 0.1 :3*pi;
y_signal = sin(2*x)+sin(1.7*x); % Random signal
threshold = 0.7; % Area lower boundary
figure(1);
clf;
hold on;
area(x, max(y_signal, threshold), threshold,'EdgeColor', 'none', 'FaceColor', 'b');
plot(x, y_signal,'k-',lsz,2);
Here is the result:
  3 Comments
Sreerag K
Sreerag K on 19 Oct 2020
Thank you. It worked fine

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!