How to use isspace() In MATLAB

The isspace() function is used to identify elements that are ASCII white spaces. isspace(‘string’) is used to find the white spaces present in the specified ‘string’.

Syntax:

isspace(‘string’)

Example 1:

Matlab




% MATLAB code for Space removal in
% string using isspace()
% Initializing a string
String = 'G F G';
 
% Calling the find() function
% along with isspace() function
% over the above string to remove
% the white spaces
New_String = String(find(~isspace(String)))


 
 

Output:

New_String = GFG

Example 2: 

Matlab




% MATLAB code for replacing space with
% null using the
% isspace() function
 
% Initializing a string
String = 'G e e k s f o r G e e k s';
String(isspace(String)) = []


 
 

Output:

String = w3wiki

How to remove space in a string in MATLAB?

In this article, we are going to discuss how to remove space from a string in MATLAB with the help of isspace(), find(), strrep(), and regexprep() functions.

Similar Reads

Using isspace()

The isspace() function is used to identify elements that are ASCII white spaces. isspace(‘string’) is used to find the white spaces present in the specified ‘string’....

Using strrep()

...

Using regexprep()

...

Using deblank()

...

Using strtrim()

...

Using erase()

The regexprep() function is used to replace text using regular expressions....

Using relational operator

...