multiple plots on a subplot
100 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I just want something generic so I can have two subplots and two graphs on each subplot. I know how to do the two subplots but having two different graphs on each subplot is the problem. Thanks
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 19 Fév 2013
Modifié(e) : Azzi Abdelmalek
le 19 Fév 2013
Use hold on
t=0:0.1:10;
y1=sin(t)
y2=cos(t)
subplot(2,1,1)
plot(t,y1)
hold on
plot(t,y2,'r')
0 commentaires
Plus de réponses (1)
Walter Roberson
le 19 Fév 2013
Should the two graphs be in the same visual axes? If so then "hold on" or "plotyy".
If not, if you are wanting to subdivide a subplot into further subplots, then you can use subplot for that with a bit of creativity.
Example: suppose you are subplotting 3 (down) x 5 (across), and you want the last in the middle row to be subdivided. That is 15 subplots, which MATLAB numbers row first -- so
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
Thus normally that subplot would be reached by subplot(3, 5, 10) -- a 3 x 5 matrix and pick element #10 out of that.
Now to subdivide that element into left and right halves, you need to imagine that the matrix was twice (two halves) as fine horizontally -- that it was 3 x 10 -- and then you figure out the element numbers that correspond to the two halves. A small calculation shows that the element numbers would be #19 and #20 of that finer grained matrix.
The step after that is to subplot() with those parameters:
subplot(3, 10, 19) or subplot(3, 10, 20)
and you would be addressing the left and right halves of the 3 x 5 element.
It is completely valid to subplot() with different granularities, as long as not of the axes that you subplot() into existence overlap any other one.
0 commentaires
Voir également
Catégories
En savoir plus sur Subplots 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!