
- 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 - Void Function
In MATLAB, every function can return a value, even if it's just an empty array or no output at all.However, you can create functions that perform actions or computations without explicitly returning a result. These functions are typically referred to as "procedures" rather than "functions," and they are often used for their side effects.
What is a "Void-Like" Function in MATLAB?
In MATLAB, a "void-like" function is a term used to describe a function that does not return any meaningful output or result but is used for its side effects, such as performing actions, modifying data, or displaying information. While every MATLAB function can technically return a value, these functions are designed to focus on their actions rather than their return values.
Creating a Void-Like Function in MATLAB
To create a "void-like" function in MATLAB, you follow the same basic structure as any other MATLAB function, but you do not explicitly return any values. Here's the basic syntax −
function voidFunction(arg1, arg2, ...) % Function body: Perform actions or computations % No explicit return statement end
In above syntax −
- voidFunction is the name of your function.
- arg1, arg2, ... represents any input arguments your function may need.
Void-like functions in MATLAB are commonly used for −
- Displaying information, messages, or results.
- Modifying data structures in-place.
- Performing actions that don't require a return value, such as saving files, plotting graphs, or updating the environment.
Examples of Void-Like Functions in MATLAB
Let us see a few examples void-Like functions in matlab −
Example 1: Function to Display Message
This function takes a message as input and displays it using fprintf, but it doesn't return any value.
function displayMessage(message) % Function to display a message fprintf('Message: %s\n', message); % No return statement end
You can call the function as shown below −
displayMessage('Hello, World!');
On execution the output will be −
>> displayMessage('Hello, World!') Message: Hello, World!;
Example 2: Void Function with Variable Modification
Let's create a void function that takes two numbers as input, calculates their sum, and displays the result without returning it −
function calculateAndDisplaySum(a, b) % Calculate the sum of 'a' and 'b' sumResult = a + b; % Display the result fprintf('The sum of %g and %g is %g\n', a, b, sumResult); end
So in matlab the function will be saved as below −

You can call the function like this in matlab command window −
>> calculateAndDisplaySum(5, 3); The sum of 5 and 3 is 8 >>
When the function is called , it will display "The sum of 5 and 3 is 8" in the MATLAB command window as shown above.
Example 3: Void Function with Actions
In this example, let's create a void function that generates a plot without returning anything −
function plotSineWave() % Generate a sine wave and plot it x = linspace(0, 2*pi, 100); y = sin(x); % Plot the sine wave plot(x, y); title('Sine Wave'); xlabel('x'); ylabel('sin(x)'); end
Let us create the function inside matlab first as shown below −

When you execute above in matlab command window the output is as follows −
>> plotSineWave()
