# How to generate multiple waveform and plot them on single window inMATLAB

Previously we discussed about,

**How to generate and plot a waveform in MATLAB**.
Now will discuss, how to generate multiple waveform and plot them on single window in MATLAB. For this, we are generating three waveform i.e. sinusoidal, cosine and sawtooth waveform of 5 Hz frequency.

Figure.1 - Screen capture of matlab program.

The matlab program for this problem with brief description has been shown in figure.1. The matlab program consists of 22 lines which is being discussed below in details:

**Line-6:**Generate the time values between 0 and 1 in interval of 0.0001 and saved into t.

**Example:**

**t = 0, 0.0001, 0.0002, 0.0003, . . . . . . . . upto 1.**

**Line-8:**Compute the values of

**ys**at each value of t using inbuilt ‘

**sin**’ function.

**Line-9:**Compute the values of

**yc**at each value of t using inbuilt ‘

**cos**’ function.

**Line-10:**Compute the values of

**yst**at each value of t using inbuilt ‘

**sawtooth**’ function.

**Line-12:**Create three subsection of plot with three rows and one column. First variable in subplot function represents number of rows, second variable represents number of column and third variable represents which section we are using to display graph. Here we are selecting first section of the plot.

**Line-13:**Plot a graph between t and ys axis using inbuilt

**‘plot’**function.

**Line-14:**Bound both (x axis and y axis) between predefined values using inbuilt

**‘axis’**function. In this line first value is lower limit of x axis, second value is upper limit of x axis, third value is lower limit of y axis and fourth value is upper limit of y axis.

**Line-15:**Write the desired title in the top of graph with using inbuilt ‘

**title**’ function. Example:

**Sinusoidal Waveform 0f 5 Hz.**

**Line-16:**Write the desired label on x axis with using inbuilt ‘

**xlabel**’ function. Example:

**Time**.

**Line-17:**Write the desired label on y axis with using inbuilt

**‘ylabel’**function. Example:

**Amplitude**.

**Line-19:**Description is similer to line 12. Here we are selecting second section of the plot.

**Line-20:**Plot a graph between

**t**and

**yc**axis using inbuilt

**‘plot’**function.

**Line-21:**Description similer to line 14.

**Line-22:**Write the desired title in the top of graph with using inbuilt ‘

**title**’ function. Example:

**Cosine Waveform 0f 5 Hz.**

**Line-23:**Description similer to line 16.

**Line-24:**Description similer to line 17.

**Line-26:**Description is similer to line 12. Here we are selecting

**third**section of the plot.

**Line-27:**Plot a graph between

**t**and

**yst**axis using inbuilt

**‘plot’**function.

**Line-28:**Description similer to line 14.

**Line-29:**Write the desired title in the top of graph with using inbuilt ‘

**title**’ function. Example:

**Sawtooth Waveform 0f 5 Hz.**

**Line-30:**Description similer to line 16.

**Line-31:**Description similer to line 17.

Plot generated using above matlab program has been shown in figure.2.

Figure.2 - Screen capture of plot generated using matlab program.

The plot generated of sinusoidal, cosine and sawtooth waveform for 5 Hz frequency i.e. 5 cycles per second.

**Video Tutorial:**How To Generate Multiple Waveform and Plot Them on Single Window in MATLAB

## Post a Comment