
Then we take y1 variable as cos(x1), then we use a plot function to plot a signal using x1 and y1 variables. First, we specify the x1 variable using the linspace function to 0 to 20. In our example, we take the value of p is 4. Let see an example for multiple plots in Matlab, we use a subplot function to plot 4 different plots for this we take subplot (2, 2, p)divides the current figure into a 2-by-2 grid, and creates axes in the position specified by p, the value of p decides the how many plots we plot. After that we replace the 4 th plot with an empty plot, for this, we use a ‘subplot (2, 2, 4, ‘replace’)’ this statement.Īs we saw a figure, the 4 th plot is replace with empty plot. Then we use a steam function with that 20 random numbers then we end the loop. Then the values of k is varied from 1 to 4. Then we use a subplot function, we use subplot (2, 2, k) divides the current figure into a 2-by-2 grid and creates axes in the position specified by k. For this, we take a for loop with value k=4 and in that for loop we use a rand function, basically rand function is used to generate a random number it this example we take 20 random numbers, so we take rand(1,20) and these 20 random numbers are assigned to the variable d. Let us see an example, we create 4 subplots for any random values and then we replace the 4 th subplot with empty axes. Then we use a scatter function to plot a 3 rd signal, scatter plot with circles at the locations specified by the vectors x and y. And now we plot a 3 rd plot take we multiply cos(x1) signal with magnitude 4 and those values assign to 圓 variable. Then we divide cos(x1) signal by 2 and assign those values to y2 and now we use plot function with x1 and y2 variables, this plot the 2 nd signal on the same axes with a different color. Now, we use a hold on, hold on retains plot in current axes so that the new plot added without deleting a previous plot. Then we assign a title for that plot using a title function. Then we plot a signal by taking x1 and y1 variables, we plot signal using a plot function, plot the data in y1 versus the corresponding values in x1. Firstly we take a linspace function to generate a linearly spaced vector and this assign to x1 variable and we take a cos(x1) signal on y1 variable. Le we see an example for multiple plots in matlab, in this example we take three signals on a single plot. Step 2: Then we use a subplot statement with appropriate syntaxįollowing are the Examples are given below: Example #1.Step 2: Then we use to hold on to plot the 2 nd signal on the same axes but different colour or style.Step 1: We take variables and assign a value and plot 1 st signal.The steps for multiple plotting of the data using subplot statement:.

MATLAB SUBPLOT HOW TO
Subplot(ax) How to Do Multiple Plots in Matlab?įor multiple plotting of the data, we use plot and subplot statement. The syntax for Multiple plots in Matlab is as shown below:. Hadoop, Data Science, Statistics & others
