From: Matt J on
"Lauren D" <ld(a)mathworks.com> wrote in message <fg8ljd$dq1$1(a)fred.mathworks.com>...
> I have to remove all punctuation and spaces from a sentence.
> I'm using a for loop and if statement to do the removal. Is
> there a function to remove all spaces in a string? If not
> what is the statement to check if a string location is ~= to
> a space? How do you specify a space in a statement?
====================

This might also help

s='I''m a cowboy. On a steel horse, I ride.';

>> regexprep(s,'[^\w'']','')

ans =

I'macowboyOnasteelhorseIride