Plot two functions in one diagramm with different y-axis limits
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Daniela Würmseer
am 24 Nov. 2022
Beantwortet: John D'Errico
am 24 Nov. 2022
Hey, i want to plot for example two functions in one diagramm as the following Code and picture:
figure
fplot(@(x) sin(x), [-5 5], 'b') %here i want a ylim form [-1 1]
hold on
fplot(@(x) cos(x), [-5 5], 'r') %here i want a ylim form [-1 0]
ylim([-1 1])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1206198/image.png)
So i want (for example) sin and cosinus plottet in one diagramm but the ylim of cos should be only from -1 to 0, so what i "covered with the green pencil should be away (or all red lines over the green line) and the y lim should be from -1 to 1.
Thanks.
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 24 Nov. 2022
Easy peasy.
x = linspace(-5,5,1000);
y1 = sin(x);
y2 = cos(x);
y2(y2 > 0) = NaN;
plot(x,y1,'b-',x,y2,'r-')
ylim([-1,1])
yline(0,'g')
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!