MATLAB: Do I receive an error when I use ‘\’ as the delimiter in the TEXTSCAN command

characterdelimiterescapeMATLABtextscan

When I execute the code:
p=cd;
textscan(p,'%s','delimiter','\');
I receive the error:
??? Error using ==> textscan
Delimiter has incorrect \ constant.

Best Answer

This change has been incorporated into the documentation in Release 2009b (R2009b). For previous releases, read below for any additional information:
This is an expected behavior in MATLAB. The character '\' is a MATLAB operator and is hence interpreted. In order to pass in the '\' character in its un-interpreted form to the TEXTSCAN command, it needs to be preceeded by the escape character '\'. Therefore, to use '\' as the delimiter in the TEXTSCAN command, execute:
textscan(p,'%s','delimiter','\\');