My query is string = \'Alligator in water\'
where in
is a stop word. How can I remove it so that I get stop_remove = \'Alligator water\'
A slightly more elegant way than Luis Mendo's solution is to use regexprep that does exactly what you want
>> result = regexprep( 'Alligator in water', 'in\s*', '' ); % replace with an empty string
result =
Alligator water
If you have several stop words you can simply add them to the pattern (in this example I consider 'in'
and 'near'
as stop words):
>> result = regexprep( 'Alligator in water near land', {'in\s*','near\s*'}, '' )
result =
Alligator water land