multiple plots on a subplot

조회 수: 145 (최근 30일)
Kyle
Kyle 2013년 2월 19일
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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 19일
편집: Azzi Abdelmalek 2013년 2월 19일
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')

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 2월 19일
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.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by