Plotting two functions with ranges in one plot
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I have trouble finding out how to put seperate ranges on my plot.
As of right now this is my code:
x=[0: 1: 6]
M1=9.*x-3.*x.^2
M2=-1.*(3.*(6-x).^2);
figure
plot(x, M1, x, M2)
grid
The first function's (M1) variable "x" should have ranges from 0 to 4 (x >= 0 and x < 4)
The second function's (M2) variable "x" should have ranges from 4 to 6 (x >= 4 and x < 6)
Anyways I need my plot to look like this:![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/240284/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/240284/image.png)
2 commentaires
Catalytic
le 28 Sep 2019
If you don't know how to generate "This", how did you obtain the left-hand plot above?
Réponse acceptée
Plus de réponses (2)
Catalytic
le 28 Sep 2019
You could also edit away the data points you don't want
h=plot(x, M1, x, M2); ylim([-120,20]);
h(1).XData(6:7)=[]; h(1).YData(6:7)=[];
h(2).XData(1:4)=[]; h(2).YData(1:4)=[];
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!