Matrix of Plots:
The other function which is very useful with any type of plot is subplot that creates a matrix of plots in the present Figure Window. The three arguments are passed to it in the form subplot(r,c,n); here r & c are the dimensions of the matrix and n is the number of the specific plot within this matrix. The plots are numbered row wise beginning in the upper left corner. In most cases, it is helpful to create a subplot in a for loop therefore the loop variable can iterate through the integers 1 through n. Whenever the subplot function is called in a loop, then the first two arguments will always be similar as they give the dimensions of the matrix. The third argument iterate through the numbers assigned to the elements of matrix. Whenever the subplot function is called, it made that element the active plot; then, any plot function can be used to complete with axis labeling, titles, and like in that element.
For illustration, the subplot below shows the distinction, in one Figure Window, between using 10 points &20 points to plot sin(x) between 0 and 2 *π . The subplot function generates a 1 × 2 row vector of plots in the Figure Window, and hence the two plots are shown side-by-side. The loop variable i iterates throughout the values 1 and then 2. The first time throughout the loop, whenever i have the value 1, 10*1 or 10 points are used, and the value of third argument to the subplot function is 1. The second time throughout the loop, 20 points are used and third argument to subplot is 2. Note that the sprintf is used to print how many points were used in the plot titles. The resultant figure Window with both plots is a shown in the figure.