Matlab

The isempty Function in MATLAB

The MATLAB isempty() function is a useful function that helps determine whether an array is empty or not. It is useful in those cases where you have to analyze big data sets and attempt to locate null or empty arrays. Analysts widely use this function to transmit data without empty values, arrays, or cells when reporting. The isempty() function is a lifesaver for data analysts in such circumstances. We will teach how to implement MATLAB’s isempty() function in this article.

How to Implement isempty() Function in MATLAB?

The isempty() is a built-in MATLAB function that is used to determine whether an array is empty or not. This function takes an array as a parameter and, in the case of an empty array, returns 1. Otherwise, it gives 0.

Syntax

This function follows a simple syntax that is given below:

isempty(x)

 
The above-mentioned syntax demonstrates that this function gets the array x as an input and will return a logical 1, which represents TRUE if x is empty. If x is not empty, the result will be logical 0, which represents FALSE.

Example 1

This is a simple MATLAB code that creates a multidirectional 7-by-7 array having all zero entries. As the array is not empty, so the isempty() function will return a logical 0.

x = zeros(7)
result = isempty(x)

 

Example 2

This MATLAB code creates a vector with 0 dimensions having character-type entries. As the array is empty, so the isempty() function will return logical 1.

str = strings(0,3)
result = isempty(str)

 

Example 3

This MATLAB code creates a 4-by-2 matrix having random numbers. After that it deletes all entries of X so now X is an empty matrix. When isempty() function is applied to X, the result will be logical 1.

X = rand(4,2)
X(:,:,:) = [];
result = isempty(X)

 

Example 4

This MATLAB code simply creates a vector having strings. So the isempty() function will return logical 0 because X is not an empty array.

X = ["welcome" "to" "linuxhint"];
result = isempty(X)

 

Conclusion

We can check whether or not an array is empty using the MATLAB isempty() function. We can also provide a string vector as an input to the isempty() function to verify the same for any string vector. By using isempty(), analysts can conveniently transmit data without empty values, arrays, or cells in their reports. In this article, we have explored the usage of MATLAB’s isempty() function, along with practical examples to help users understand its behavior.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.