How to use relational operator In MATLAB
Now, let’s see two different methods for space removal by using relational operators and the concept of the null space. Here we use equality (== ) and inequality (~=) relational operators. Relational operators compare operands quantitatively, using different operators.
Example 1:
Matlab
% MATLAB code for space removal in string % using equality operator % Initializing a string String = 'G e e k s f o r G e e k s' ; % Changing the above String by setting % locations with spaces equal to null String(String == ' ' ) = [] |
Output:
String = w3wiki
Example 2:
Matlab
% MATLAB code for Space removal % in string using inequality and non-space % elements method String = 'G e e k s f o r G e e k s' ; % Extracting non-space elements New_String = String(String ~= ' ' ) |
Output:
New_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.