EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • All Courses
    • All Specializations
  • Blog
  • Enterprise
  • Free Courses
  • All Courses
  • All Specializations
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial isempty MATLAB
 

isempty MATLAB

Priya Pedamkar
Article byPriya Pedamkar

Updated March 4, 2023

isempty MATLAB

 

 

Introduction to isempty function in MATLAB

MATLAB is a programming environment that is interactive and is used in scientific computing. It is extensively used in a lot of technical fields where problem-solving, data analysis, algorithm development, and experimentation is required. The software which is discipline-specific is extensively written using MATLAB. In this article, we will study how to use ‘isempty’ function in MATLAB. Before we start learning how ‘isempty’ function works in MATLAB, let us refresh our understanding of why we need ‘isempty’ function.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

We use ‘isempty’ function on an array to check if the array is empty or otherwise. It is a very handy tool in data analysis where we have large sets of data and want to identify null or empty arrays. Sometimes in reporting, analysts need to send data without the empty values/arrays/cells. In such cases, isempty function becomes a life savior for data analysts.

Syntax

Let us now understand the syntax of ‘isempty’ function in MATLAB:

IE = isempty (X)

[Please keep in mind that isempty is a logical function and returns 0 or 1 as output]

Explanation: This function will return logical 1, signifying TRUE, if X is empty, The output will be logical 0, signifying FALSE, if X is not empty. If we have an empty array with a minimum one of its dimensions as length 0, ‘isempty’ will return 1 as output. [i.e an array of the form ‘0 X 3’ or ‘3 X 0’ etc.]

Examples to Implement isempty MATLAB

Let us now understand how the code for ‘isempty’ function looks like in MATLAB, with the help of various examples.

Example #1

In the first example, let us take an array of dimension 3 x 0 and see how the ‘isempty’ function works.

Code:

X = rand (3, 0)
IE = isempty (X)

Output:

array of dimension

Explanation: Defining the input array with dimensions 3 x 0. Calling the isempty function using the input array ‘X’. As we can see in the output, we have obtained logical 1 for an array of dimension 3 x 0, as expected by us.

Example #2

Let us take an array with dimensions 0 x 4 and see how the ‘isempty’ function works.

Code:

X = rand (0, 4)
IE = isempty (X)

Output:

isempty MatLab2

Explanation: Defining the input array with dimensions 0 x 4. Calling the isempty function using the input array ‘X’. As we can see in the output, we have obtained logical 1 for an array of dimension 0 x 4, as expected by us.

Example #3

Let us now take an array with dimensions that are not equal to zero and see how the results vary. We will be taking an array of dimensions 3 x 3 and see how the ‘isempty’ function works.

Code:

X = rand (3, 3)
IE = isempty (X)

Output:

not equal to zero

Explanation: Defining the input array with dimensions 3 x 3. Calling the isempty function using the input array ‘X’. As we can see in the output, we have obtained logical 0 for an array of dimension 3 x 3, as expected by us. A very important point to remember here is that ‘isempty’ function identifies empty arrays AND NOT the arrays with all the values as zero.

Example #4

Let us now take an array with dimensions that are not equal to zero, but all its elements are equal to zero.

Code:

X = zeros (3, 3)
IE = isempty (X)

Output:

isempty MatLab4

Explanation: Defining the input array with dimensions 3 x 3 and all the elements as zero. Calling the isempty function using the input array ‘X’. As we can see in the output, we have obtained logical 0 for an array of dimension 3 x 3 and all the elements as ‘0’. So, this can be concluded that an array with all the elements as zero, is not considered as an empty array. isempty function in MATLAB can also be used for a string array. Let us learn how to find out if a string array is empty or not using the ‘isempty’ function.

Example #4

Let us now take a string array with dimensions that are not equal to zero.

Code:

X = ["is"  "empty"  "function"] IE = isempty (X)

Output:

isempty MatLab5

Explanation: Defining the input string array with dimensions 1 x 3. Calling the isempty function using the input string array ‘X’. So, we have obtained logical 0 as our output since the input string array in our example is not empty.

Conclusion

MATLAB provides us with an ‘isempty’ function to check if the array is empty or not. Further, we can also check the same for a string vector by passing it as an argument to ‘isempty’ function. An important thing with ‘isempty’ function is that it checks for empty arrays, which should not be confused with arrays containing all zeros.

Recommended Articles

This is a guide to isempty MATLAB. Here we discuss an introduction to isempty MATLAB, syntax, with programming examples with explanation. You can also go through our other related articles to learn more –

  1. MATLAB Exponential
  2. Matlab traps()
  3. Matlab Sine Wave
  4. Curve Fitting Matlab
  5. Heaviside MATLAB
Primary Sidebar
Footer
Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW