Removing Whitespace Characters:
The MATLAB has functions which will eliminate trailing blanks from the end of a string and/or leading blanks from the starting of a string.
The deblank function will eliminate blank spaces from end of the string. For illustration, when few strings are padded in a string matrix so that all are of similar length, it is often preferred to then eliminate those extra blank spaces in order to actually use the string.
>> names = char('Sue', 'Cathy','Xavier')
names =
Sue
Cathy
Xavier
>> name1 = names(1,:)
name1 =
Sue
>> length(name1)
ans =
6
>> name1 = deblank(name1);
>> length(name1)
ans =
3