How to fill the plot to some specific value
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kai Wang
am 27 Jan. 2024
Bearbeitet: Star Strider
am 27 Jan. 2024
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1601436/image.png)
0 Kommentare
Akzeptierte Antwort
Star Strider
am 27 Jan. 2024
Bearbeitet: Star Strider
am 27 Jan. 2024
Try this —
t = linspace(0, 2*pi, 500);
s = sin(t);
figure
plot(t, s, 'LineWidth',1.5)
Lv1 = s >= 0.5;
Lv2 = s <= -0.5;
hold on
patch([t(Lv1) flip(t(Lv1))], [0.5*ones(size(s(Lv1))) flip(s(Lv1))], 'b', 'FaceAlpha',0.25, 'EdgeColor','none')
patch([t(Lv2) flip(t(Lv2))], [-0.5*ones(size(s(Lv2))) flip(s(Lv2))], 'b', 'FaceAlpha',0.25, 'EdgeColor','none')
hold off
Ax = gca;
Ax.XAxisLocation = 'origin';
Ax.XMinorTick = 'on';
Ax.YMinorTick = 'on';
Make appropriate changes to get the result you want.
EDIT — Added minor ticks.
.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!