
- MATLAB - Home
- MATLAB - Overview
- MATLAB - Features
- MATLAB - Environment Setup
- MATLAB - Editors
- MATLAB - Online
- MATLAB - Workspace
- MATLAB - Syntax
- MATLAB - Variables
- MATLAB - Commands
- MATLAB - Data Types
- MATLAB - Operators
- MATLAB - Dates and Time
- MATLAB - Numbers
- MATLAB - Random Numbers
- MATLAB - Strings and Characters
- MATLAB - Text Formatting
- MATLAB - Timetables
- MATLAB - M-Files
- MATLAB - Colon Notation
- MATLAB - Data Import
- MATLAB - Data Output
- MATLAB - Normalize Data
- MATLAB - Predefined Variables
- MATLAB - Decision Making
- MATLAB - Decisions
- MATLAB - If End Statement
- MATLAB - If Else Statement
- MATLAB - If…Elseif Else Statement
- MATLAB - Nest If Statememt
- MATLAB - Switch Statement
- MATLAB - Nested Switch
- MATLAB - Loops
- MATLAB - Loops
- MATLAB - For Loop
- MATLAB - While Loop
- MATLAB - Nested Loops
- MATLAB - Break Statement
- MATLAB - Continue Statement
- MATLAB - End Statement
- MATLAB - Arrays
- MATLAB - Arrays
- MATLAB - Vectors
- MATLAB - Transpose Operator
- MATLAB - Array Indexing
- MATLAB - Multi-Dimensional Array
- MATLAB - Compatible Arrays
- MATLAB - Categorical Arrays
- MATLAB - Cell Arrays
- MATLAB - Matrix
- MATLAB - Sparse Matrix
- MATLAB - Tables
- MATLAB - Structures
- MATLAB - Array Multiplication
- MATLAB - Array Division
- MATLAB - Array Functions
- MATLAB - Functions
- MATLAB - Functions
- MATLAB - Function Arguments
- MATLAB - Anonymous Functions
- MATLAB - Nested Functions
- MATLAB - Return Statement
- MATLAB - Void Function
- MATLAB - Local Functions
- MATLAB - Global Variables
- MATLAB - Function Handles
- MATLAB - Filter Function
- MATLAB - Factorial
- MATLAB - Private Functions
- MATLAB - Sub-functions
- MATLAB - Recursive Functions
- MATLAB - Function Precedence Order
- MATLAB - Map Function
- MATLAB - Mean Function
- MATLAB - End Function
- MATLAB - Error Handling
- MATLAB - Error Handling
- MATLAB - Try...Catch statement
- MATLAB - Debugging
- MATLAB - Plotting
- MATLAB - Plotting
- MATLAB - Plot Arrays
- MATLAB - Plot Vectors
- MATLAB - Bar Graph
- MATLAB - Histograms
- MATLAB - Graphics
- MATLAB - 2D Line Plot
- MATLAB - 3D Plots
- MATLAB - Formatting a Plot
- MATLAB - Logarithmic Axes Plots
- MATLAB - Plotting Error Bars
- MATLAB - Plot a 3D Contour
- MATLAB - Polar Plots
- MATLAB - Scatter Plots
- MATLAB - Plot Expression or Function
- MATLAB - Draw Rectangle
- MATLAB - Plot Spectrogram
- MATLAB - Plot Mesh Surface
- MATLAB - Plot Sine Wave
- MATLAB - Interpolation
- MATLAB - Interpolation
- MATLAB - Linear Interpolation
- MATLAB - 2D Array Interpolation
- MATLAB - 3D Array Interpolation
- MATLAB - Polynomials
- MATLAB - Polynomials
- MATLAB - Polynomial Addition
- MATLAB - Polynomial Multiplication
- MATLAB - Polynomial Division
- MATLAB - Derivatives of Polynomials
- MATLAB - Transformation
- MATLAB - Transforms
- MATLAB - Laplace Transform
- MATLAB - Laplacian Filter
- MATLAB - Laplacian of Gaussian Filter
- MATLAB - Inverse Fourier transform
- MATLAB - Fourier Transform
- MATLAB - Fast Fourier Transform
- MATLAB - 2-D Inverse Cosine Transform
- MATLAB - Add Legend to Axes
- MATLAB - Object Oriented
- MATLAB - Object Oriented Programming
- MATLAB - Classes and Object
- MATLAB - Functions Overloading
- MATLAB - Operator Overloading
- MATLAB - User-Defined Classes
- MATLAB - Copy Objects
- MATLAB - Algebra
- MATLAB - Linear Algebra
- MATLAB - Gauss Elimination
- MATLAB - Gauss-Jordan Elimination
- MATLAB - Reduced Row Echelon Form
- MATLAB - Eigenvalues and Eigenvectors
- MATLAB - Integration
- MATLAB - Integration
- MATLAB - Double Integral
- MATLAB - Trapezoidal Rule
- MATLAB - Simpson's Rule
- MATLAB - Miscellenous
- MATLAB - Calculus
- MATLAB - Differential
- MATLAB - Inverse of Matrix
- MATLAB - GNU Octave
- MATLAB - Simulink
MATLAB - Plot Sine Wave
Plotting sine waves in MATLAB allows you to visualize periodic signals and study their characteristics. Sine waves are fundamental in signal processing, communication systems, and many other fields. MATLAB provides simple and powerful functions for generating and visualizing sine waves.
In MATLAB, there are various functions available to facilitate sine wave plotting. These include −
- plot() function
- fplot() function
- ezplot() function
- stem() function
- polarplot() function
Using plot() function
The plot() function in MATLAB is a fundamental tool for creating 2D plots of data. It allows you to visualize relationships and patterns in your data by plotting points and connecting them with lines. With plot(), you can create various types of plots, including line plots, scatter plots, and more, making it a versatile tool for data analysis and visualization.
Syntax
plot(X, Y)
plot(X,Y) is used in MATLAB to create a 2D plot where X and Y are vectors representing the x and y coordinates of the points to be plotted. Each pair of corresponding elements in X and Y defines a point on the plot. The plot() function connects these points with lines, creating a line plot.
Example 1: Plotting sine wave using plot()
The code we have is as follows −
t = 0:0.01:2*pi; y = sin(t); plot(t, y);
- In this example, we first define a time vector t using the colon operator (:) to generate values from 0 to 2*pi with a step size of 0.01.
- Next, we compute the sine values y corresponding to each time value in t using the sin() function.
- Finally, we use the plot() function to plot the sine wave, with t as the x-values and y as the y-values. This creates a plot of the sine wave with time on the x-axis and amplitude on the y-axis.
When the code is executed in matlab command window the output we get is as follows −

Example 2: Plotting a Sine Wave with 10 Hz Frequency
The code we have is −
f = 10; a = 1; phi = 0; t = 0:1/(f*100):1; y = a * sin(2*pi*f*t + phi); plot(t, y);
In the example above −
- The code defines a sine wave with a frequency of 10 Hz (f = 10), an amplitude of 1 volt (a = 1), and a phase of 0 radians (phi = 0).
- It generates a time vector t from 0 to 1 second with a step size corresponding to the frequency, ensuring that the sine wave completes one cycle within the specified time range.
- The sine wave equation y = a * sin(2*pi*f*t + phi) computes the values of the sine wave at each time point in t, taking into account the frequency, amplitude, phase, and time vector.
- Finally, the plot() function is used to plot the sine wave, and labels and a title are added to the plot for clarity.
When the code is executed the output we get is as follows −

Using fplot() function
The fplot() function in MATLAB is used to plot a function over a specified range. It is particularly useful for visualizing mathematical functions, including trigonometric functions like sine waves. Unlike the plot() function, which requires explicit calculation of function values, fplot() can directly plot functions of the form y = f(x).
Syntax
fplot(fun, [xmin, xmax])
fplot(fun, [xmin, xmax]) : Here fun: The function to be plotted. It can be an anonymous function or a function handle.[xmin, xmax]: The range of x values over which the function should be plotted.
Example: Plotting Sine Wave Using fplot()
The code we have is as follows −
fun = @(x) sin(2*pi*60*x); fplot(fun, [0, 1/60]);
In above example
- We have an anonymous function fun representing a sine wave with a frequency of 60 Hz.
- The fplot() function is used to plot the sine wave over one cycle (0 to 1/60 seconds).
- The x-axis represents time in seconds, and the y-axis represents the amplitude of the sine wave.
When you execute the code the output is as follows −

Using ezplot() function
The ezplot() function in MATLAB is used to plot implicit and explicit equations in 2D. It is particularly useful for visualizing mathematical expressions without the need to explicitly define a function. ezplot() can handle both single-variable and parametric expressions, making it versatile for various plotting tasks.
Syntax
ezplot(equation) ezplot(equation, [xmin, xmax])
- Equation − The equation to be plotted. It can be an explicit equation y = f(x) or an implicit equation f(x, y) = 0.
- [xmin, xmax] − (Optional) The range of x values over which the equation should be plotted.
Example: Plotting a Sine Wave using ezplot()
The code we have is −
ezplot('sin(x)', [0, 2*pi])
In above code we have is −
- The ezplot() function is used to plot the sine wave y = sin(x) over the range [0, 2*pi].
- The equation 'sin(x)' represents the sine function sin(x), where x is the independent variable.
- The range [0, 2*pi] specifies the x-axis limits over which the sine wave is plotted, covering one full period of the sine function.
When we execute the code, the output is −

With just ezplot(sin(x)), the output we get is as follows −

Using stem() function
The stem() function in MATLAB is used to create stem plots, which are similar to traditional plots but represent data as discrete points above a baseline. Stem plots are commonly used for visualizing discrete data, such as time-series data or signal samples.
Syntax
stem(Y) stem(X, Y)
Y − Vector of data values to be plotted.
X − Optional vector of x-coordinates corresponding to the data values in Y.
Example: Simple Stem Plot of a Sine Wave
The code we have is as follows −
t = 0:0.1:2*pi; y = sin(t); stem(t, y);
In this example, we create a time vector t and compute the sine values y.
- The stem() function is used to plot the sine wave, with t as the x-coordinates and y as the y-coordinates.
- The plot represents the discrete samples of the sine wave as stems rising from the x-axis at each time point.
When the code is executed the output is as follows −

Using polarplot() function
The polarplot() function in MATLAB is used to create polar plots, which are plots that use polar coordinates instead of Cartesian coordinates. Polar plots are particularly useful for visualizing periodic functions, such as sine waves, or data that is naturally represented in polar form.
Syntax
polarplot(theta, rho)
- theta − Vector of angles (in radians) for each data point.
- rho − Vector of radial distances from the origin for each data point.
Example: Plotting sinewave using polarplot()
The code we have is −
theta = 0:0.01:2*pi; rho = sin(theta); polarplot(theta, rho);
In this example,
- We define an angle vector theta ranging from 0 to 2*pi (one full revolution) with a small step size.
- We compute the radial distances rho as the sine values corresponding to each angle in theta.
- The polarplot() function is used to plot the sine wave in polar coordinates, with theta as the angles and rho as the radial distances.
- The resulting plot shows the sine wave as a spiral around the origin, with the distance from the origin representing the amplitude of the sine wave at each angle.
When the code is executed the output we get is as follows −
