

Finally our last plot occupies the second row, third column using subplot(2,3,6). This occupies the second row, and first and second columns. The second plot occupies slots p=4,p=5 using subplot(2,3,4:5). In other words: figure Īs you can see, we have occupied the first row using subplot(2,3,1:3) with the first plot. You can then issue more plots in slots 4, 5 and 6. As an example, if you did: subplot(2,3,1:3), this will take one plot and occupy the entire first row of your figure. If you specify p to be a vector, what this will do is that one plot you make will occupy multiple spaces / slots within the same figure window. If p is a single number, then either subplot(m,n,p) or subplot(mnp) will work. However, should you do it this way, you must call subplot this way: subplot(m,n,p). You can also specify a vector of points for p.
#MATLAB SUBPLOT IMAGES CODE#
The figure that the code above describes looks like the following: You must make sure that you know how many figures you want within the overall window before you start plotting. Notice that the last parameter of subplot increases linearly, while the first two parameters stay the same. What the above code does is that we generate random sets of points that are 100 x 1 each for pairs of x and y and we plot them in multiple locations within the overall window. Let's create a window that has two rows and three columns worth of figures within the same window.

Determine how many rows and columns of plots you want within this window first (i.e.How you use subplot is in the following fashion: When you do subplot(1,2,2) or subplot(122), this is when p=2 and you wish to place the plot in the right most column. The last number, p=1 means that you wish to place the plot in the left most column. In this case, when you do subplot(1,2,1) or subplot(121), you would like to have one row and two columns worth of figures.

The number p increases from 1 up to m x n, and the plots are placed from left to right, and top to bottom. p determines where you want to place your plot within the grid. You can place plots within a m x n grid, where m contains the number of rows and n contains the number of columns in your figure. subplot places multiple figures within the same window. You have three numbers that are used within subplot. How subplot works is the following: subplot(m,n,p) %//or Long story short, there is no difference.
